How do I open the watch app from the parent iOS app?

I need to open a chat extension from my parent iOS app. I've seen a similar feature implemented in the Nike + Run Club app. those. when the user pressed the start button in the parent app, the clock set extension will instantly open.

+3


source to share


1 answer


As @abjurato said, you can only run it in 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
    }
}

      

+5


source







All Articles