How to Programmatically Open Apple Watch Companion App from iOS App

How to programmatically open Apple Watch companion app from iOS app

I guess it's not possible to programmatically launch the watch companion app from iOS. The opposite way would be possible: to launch the iOS app in the background upon receiving a message from the watch. See WWDC talk Introducing Watch Connectivity.

You could check WCSession.defaultSession().watchAppInstalled and ask the user to launch the app if it is true.

How to open a watch app from parent iOS app?

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
}
}

Open Apple Watch app from another watch app

The documentation of the openSystemURL(_:) method clearly states that the URL supplied to it has to support the tel: or sms: scheme and can only be used for starting a phone call or writing messages. It cannot be used to open any other applications, especially not 3rd party ones.

watchOS doesn't support URL schemes at the moment (as of watchOS 5), unlike iOS, so you won't be able to open other apps from your app's WatchKit Extension.

Make phone call from Apple watch app

openURL is silently ignored if the device is locked or the app is in the background. Additionally WatchKit doesn't contain an API for initiating a phone call.

Your best bet may be to prompt the user to open the iPhone app, possibly using Handoff, and tap a button to initiate the call from there. Not a great solution, but WatchKit is pretty limited right now.



Related Topics



Leave a reply



Submit