I need to open my watch extension from my parent iOS app. I have seen a similar feature implemented in Nike+ Run Club app. ie, When the User taps on Start button in Parent app will open the watch kit extension instantly.
Asked
Active
Viewed 3,468 times
6
-
2this is done via startWatchApp(with:completion:) method of HKHealthStore. iOS app configures workout, sends it to watch and watch can start it or not, but that can be done only while iOS app is foreground. https://developer.apple.com/reference/healthkit/hkhealthstore/1648358-startwatchapp – abjurato Mar 27 '17 at 14:42
1 Answers
12
As @abjurato said, you can only launch it in a "workout mode"
import HealthKit
import WatchConnectivity
let healthStore = HKHealthStore()
func startWatchApp() {
print("method called to open app ")
getActiveWCSession { (wcSession) in
print(wcSession.isComplicationEnabled, wcSession.isPaired)
if wcSession.activationState == .activated && wcSession.isWatchAppInstalled {
print("starting watch app")
self.healthStore.startWatchApp(with: self.configuration, completion: { (success, error) in
// Handle errors
})
}
else{
print("watch not active or not installed")
}
}
}
func getActiveWCSession(completion: @escaping (WCSession)->Void) {
guard WCSession.isSupported() else { return }
let wcSession = WCSession.default()
wcSession.delegate = self
if wcSession.activationState == .activated {
completion(wcSession)
} else {
wcSession.activate()
wcSessionActivationCompletion = completion
}
}

pawisoon
- 1,427
- 1
- 15
- 20
-
2Unfortunately this will not wake the watch. Once the watch wakes up the watch app is immediately bought to the foreground, the documentation is very misleading in this sense. – Joe Maher Apr 23 '18 at 01:02