Skip to content

Commit

Permalink
#70 Added Transfer of route names to apple watch
Browse files Browse the repository at this point in the history
  • Loading branch information
Peyton-McKee committed Dec 2, 2022
1 parent 1b29cec commit ba8f79e
Show file tree
Hide file tree
Showing 19 changed files with 293 additions and 193 deletions.
89 changes: 89 additions & 0 deletions Shared/Connectivity.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// Connectivity.swift
// Trailblazer Watch App
//
// Created by Peyton McKee on 11/14/22.
//

import Foundation

import WatchConnectivity

final class Connectivity : NSObject, ObservableObject {
@Published var routeName: [String] = []
static let shared = Connectivity()

override private init() {
super.init()
#if !os(watchOS)
guard WCSession.isSupported() else {
print("session is not supported on watch os")
return
}
#endif
WCSession.default.delegate = self
print("activated session")
WCSession.default.activate()
}
public func send(routeName : [String])
{
#if os(watchOS)
guard WCSession.default.isCompanionAppInstalled else {
print("Companion App is not installed")
return }
#else
guard WCSession.default.isWatchAppInstalled else {
print("Watch app is not installed")
return }
#endif
guard WCSession.default.activationState == .activated else {
print("Session is not Active")
return }
let routeInfo: [String: [String]] = [ConnectivityTypes.route.rawValue : routeName]
print("Sent User Info")
WCSession.default.sendMessage(routeInfo, replyHandler: nil)
}

private func update(from dictionary: [String: Any])
{
let key = ConnectivityTypes.route.rawValue
guard let name = dictionary[key] as? [String] else { return }
DispatchQueue.main.async {
self.routeName = name
}
}
}

extension Connectivity: WCSessionDelegate
{
func session(_ session: WCSession, didReceiveUserInfo userInfo: [String : Any] = [:]) {
print("Received Transfer")
update(from: userInfo)
}
func session(_ session: WCSession, didFinish userInfoTransfer: WCSessionUserInfoTransfer, error: Error?) {
print("Finished Transfer")
}
func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {
print("Received Message")
update(from: message)
}
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
guard let error = error else {
print("Activation Status: \(activationState)")
return
}
print("Error: \(error.localizedDescription)")
}

#if os(iOS)
func sessionDidBecomeInactive(_ session: WCSession) {

}

func sessionDidDeactivate(_ session: WCSession) {
WCSession.default.activate()
}
#endif


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,25 @@ enum ConnectivityTypes: String
{
case route = "route"
}
struct Route: Identifiable{
struct Route: Identifiable {
var id: Int
var annotationName: String
var coordinates: [Double]
}

final class ConnectivityController: NSObject, ObservableObject {
static let shared = ConnectivityController()

@Published var route : [Route] = []

private var cancellable: Set<AnyCancellable> = []

override private init() {
super.init()
Connectivity.shared.$routeIds
.dropFirst()
.map{ ids in self.route.filter { ids.contains($0.id) } }
.receive(on: DispatchQueue.main)
.assign(to: \.route, on: self)
.store(in: &cancellable)
}

private func updateCompanion() {
let ids = route.map { $0.id }
Connectivity.shared.send(routeIds: ids)
let names = route.map { $0.annotationName }
Connectivity.shared.send(routeName: names)
}

public func setRoute(route: [Route])
Expand Down
File renamed without changes.
85 changes: 74 additions & 11 deletions SundayRiver.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
153B2E3C28ED1EDF00A23163 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 153B2E3B28ED1EDF00A23163 /* User.swift */; };
153B2E3E28EDF26300A23163 /* CustomMKPolyline.swift in Sources */ = {isa = PBXBuildFile; fileRef = 153B2E3D28EDF26300A23163 /* CustomMKPolyline.swift */; };
153DAB9829255CFC001ABAAD /* MapInterpreter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 153DAB9729255CFC001ABAAD /* MapInterpreter.swift */; };
153DABAD2936C44A001ABAAD /* Trailblazer Watch App.app in Embed Watch Content */ = {isa = PBXBuildFile; fileRef = 1591DBB6291AE7B800978FD8 /* Trailblazer Watch App.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
153DABB12937CF61001ABAAD /* TrailsDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15545B0F28E22CCC005D0886 /* TrailsDatabase.swift */; };
153DABB22937D17E001ABAAD /* Trail.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15545B0D28E224C8005D0886 /* Trail.swift */; };
153DABB32937D188001ABAAD /* DijsktrasGraphStructure.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15545B0B28E224A2005D0886 /* DijsktrasGraphStructure.swift */; };
15489A492922AF2F00898FD0 /* Connectivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15489A482922AF2F00898FD0 /* Connectivity.swift */; };
15489A4A2922AFAC00898FD0 /* Connectivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15489A482922AF2F00898FD0 /* Connectivity.swift */; };
15489A4C2922BAD100898FD0 /* ConnectivityController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15489A4B2922BAD100898FD0 /* ConnectivityController.swift */; };
Expand All @@ -59,11 +63,36 @@
15874A0E27D82AFA001B9025 /* Scraper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15874A0D27D82AFA001B9025 /* Scraper.swift */; };
1591DBB12916D9BE00978FD8 /* CancelTrailReportView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1591DBB02916D9BE00978FD8 /* CancelTrailReportView.swift */; };
1591DBB9291AE7B800978FD8 /* TrailblazerApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1591DBB8291AE7B800978FD8 /* TrailblazerApp.swift */; };
1591DBBB291AE7B800978FD8 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1591DBBA291AE7B800978FD8 /* ContentView.swift */; };
1591DBBD291AE7B900978FD8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1591DBBC291AE7B900978FD8 /* Assets.xcassets */; };
1591DBC0291AE7B900978FD8 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1591DBBF291AE7B900978FD8 /* Preview Assets.xcassets */; };
15F92C522939A7B000792054 /* HomePageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F92C512939A7B000792054 /* HomePageView.swift */; };
15F92C542939A97D00792054 /* DirectionsDisplayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F92C532939A97D00792054 /* DirectionsDisplayView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
153DABAE2936C44A001ABAAD /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 158749EC27D82635001B9025 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 1591DBB5291AE7B800978FD8;
remoteInfo = "Trailblazer Watch App";
};
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
153DABB02936C44A001ABAAD /* Embed Watch Content */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "$(CONTENTS_FOLDER_PATH)/Watch";
dstSubfolderSpec = 16;
files = (
153DABAD2936C44A001ABAAD /* Trailblazer Watch App.app in Embed Watch Content */,
);
name = "Embed Watch Content";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
150C6EAE29031BD70055AD59 /* SideMenuFramework.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideMenuFramework.swift; sourceTree = "<group>"; };
150C6EB029035BE10055AD59 /* HextoColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HextoColor.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -119,9 +148,10 @@
1591DBB02916D9BE00978FD8 /* CancelTrailReportView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CancelTrailReportView.swift; sourceTree = "<group>"; };
1591DBB6291AE7B800978FD8 /* Trailblazer Watch App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Trailblazer Watch App.app"; sourceTree = BUILT_PRODUCTS_DIR; };
1591DBB8291AE7B800978FD8 /* TrailblazerApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrailblazerApp.swift; sourceTree = "<group>"; };
1591DBBA291AE7B800978FD8 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
1591DBBC291AE7B900978FD8 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
1591DBBF291AE7B900978FD8 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
15F92C512939A7B000792054 /* HomePageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePageView.swift; sourceTree = "<group>"; };
15F92C532939A97D00792054 /* DirectionsDisplayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DirectionsDisplayView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -234,6 +264,23 @@
path = InteractiveMap.Utils;
sourceTree = "<group>";
};
153DABAB2936B9C8001ABAAD /* Shared */ = {
isa = PBXGroup;
children = (
15545B1728E297CA005D0886 /* Game Test.gpx */,
15489A482922AF2F00898FD0 /* Connectivity.swift */,
15489A4B2922BAD100898FD0 /* ConnectivityController.swift */,
);
path = Shared;
sourceTree = "<group>";
};
153DABAC2936C44A001ABAAD /* Frameworks */ = {
isa = PBXGroup;
children = (
);
name = Frameworks;
sourceTree = "<group>";
};
15545B0428E022A5005D0886 /* ViewControllers */ = {
isa = PBXGroup;
children = (
Expand All @@ -251,8 +298,10 @@
isa = PBXGroup;
children = (
158749F627D82635001B9025 /* SundayRiver */,
153DABAB2936B9C8001ABAAD /* Shared */,
1591DBB7291AE7B800978FD8 /* Trailblazer Watch App */,
158749F527D82635001B9025 /* Products */,
153DABAC2936C44A001ABAAD /* Frameworks */,
);
sourceTree = "<group>";
};
Expand All @@ -275,7 +324,6 @@
15545B0428E022A5005D0886 /* ViewControllers */,
159B0EC628E68DDC00DAFEAA /* TrailDatabaseFiles */,
150D063728FB020B0051F160 /* Utils */,
15545B1728E297CA005D0886 /* Game Test.gpx */,
15874A0027D82636001B9025 /* Assets.xcassets */,
150D063E290063900051F160 /* Images */,
15874A0227D82636001B9025 /* LaunchScreen.storyboard */,
Expand All @@ -290,9 +338,8 @@
children = (
152C69B8291B3A750092E537 /* Trailblazer Watch App.entitlements */,
1591DBB8291AE7B800978FD8 /* TrailblazerApp.swift */,
1591DBBA291AE7B800978FD8 /* ContentView.swift */,
15489A482922AF2F00898FD0 /* Connectivity.swift */,
15489A4B2922BAD100898FD0 /* ConnectivityController.swift */,
15F92C512939A7B000792054 /* HomePageView.swift */,
15F92C532939A97D00792054 /* DirectionsDisplayView.swift */,
1591DBBC291AE7B900978FD8 /* Assets.xcassets */,
1591DBBE291AE7B900978FD8 /* Preview Content */,
);
Expand Down Expand Up @@ -327,10 +374,12 @@
158749F027D82635001B9025 /* Sources */,
158749F127D82635001B9025 /* Frameworks */,
158749F227D82635001B9025 /* Resources */,
153DABB02936C44A001ABAAD /* Embed Watch Content */,
);
buildRules = (
);
dependencies = (
153DABAF2936C44A001ABAAD /* PBXTargetDependency */,
);
name = SundayRiver;
productName = SundayRiver;
Expand Down Expand Up @@ -471,15 +520,27 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1591DBBB291AE7B800978FD8 /* ContentView.swift in Sources */,
15F92C542939A97D00792054 /* DirectionsDisplayView.swift in Sources */,
1591DBB9291AE7B800978FD8 /* TrailblazerApp.swift in Sources */,
15489A4C2922BAD100898FD0 /* ConnectivityController.swift in Sources */,
153DABB12937CF61001ABAAD /* TrailsDatabase.swift in Sources */,
153DABB22937D17E001ABAAD /* Trail.swift in Sources */,
153DABB32937D188001ABAAD /* DijsktrasGraphStructure.swift in Sources */,
15F92C522939A7B000792054 /* HomePageView.swift in Sources */,
15489A492922AF2F00898FD0 /* Connectivity.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
153DABAF2936C44A001ABAAD /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 1591DBB5291AE7B800978FD8 /* Trailblazer Watch App */;
targetProxy = 153DABAE2936C44A001ABAAD /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
158749FD27D82635001B9025 /* Main.storyboard */ = {
isa = PBXVariantGroup;
Expand Down Expand Up @@ -701,14 +762,15 @@
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = Trailblazer;
INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "This app uses your location to personalize your experience";
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = "";
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = .trailblazerIOS;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = .trailblazerWatchOS;
PRODUCT_BUNDLE_IDENTIFIER = .trailblazerIOS.trailblazerWatchOS;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = watchos;
Expand All @@ -735,14 +797,15 @@
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = Trailblazer;
INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "This app uses your location to personalize your experience";
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = "";
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = .trailblazerIOS;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = .trailblazerWatchOS;
PRODUCT_BUNDLE_IDENTIFIER = .trailblazerIOS.trailblazerWatchOS;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = watchos;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</BuildableReference>
</BuildableProductRunnable>
<LocationScenarioReference
identifier = "../../SundayRiver/Game Test.gpx"
identifier = "../../Shared/Game Test.gpx"
referenceType = "0">
</LocationScenarioReference>
</LaunchAction>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
filePath = "SundayRiver/TrailDatabaseFiles/TrailsDatabase.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "299"
endingLineNumber = "299"
startingLineNumber = "300"
endingLineNumber = "300"
landmarkName = "TrailsDatabase"
landmarkType = "3">
<Locations>
Expand Down Expand Up @@ -221,8 +221,8 @@
filePath = "SundayRiver/ViewControllers/InteractiveMapViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "874"
endingLineNumber = "874"
startingLineNumber = "875"
endingLineNumber = "875"
landmarkName = "presentTrailReportMenu()"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -237,8 +237,8 @@
filePath = "SundayRiver/ViewControllers/InteractiveMapViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "875"
endingLineNumber = "875"
startingLineNumber = "876"
endingLineNumber = "876"
landmarkName = "presentTrailReportMenu()"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -253,8 +253,8 @@
filePath = "SundayRiver/ViewControllers/InteractiveMapViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "910"
endingLineNumber = "910"
startingLineNumber = "911"
endingLineNumber = "911"
landmarkName = "presentRouteOverviewMenu()"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -269,8 +269,8 @@
filePath = "SundayRiver/ViewControllers/InteractiveMapViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "841"
endingLineNumber = "841"
startingLineNumber = "842"
endingLineNumber = "842"
landmarkName = "showAllTrails()"
landmarkType = "7">
</BreakpointContent>
Expand Down
Binary file modified SundayRiver/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion SundayRiver/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
) {
print("Failed to register: \(error)")
}

private func configureUserNotifications() {
UNUserNotificationCenter.current().delegate = self
}
Expand Down
Loading

0 comments on commit ba8f79e

Please sign in to comment.