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.
How to open a watch app from parent iOS app?
Asked Answered
this 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. developer.apple.com/reference/healthkit/hkhealthstore/… –
Unbowed
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
}
}
Unfortunately 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. –
Mcmorris
© 2022 - 2024 — McMap. All rights reserved.