How to programmatically open Apple Watch companion app from iOS app

家住魔仙堡 提交于 2019-12-18 07:05:32

问题


I would like to give a hint to the user, that my iOS app supports the Apple Watch.

So I would like to link/open the Apple Watch companion app from within my iOS app, very much similar to opening the Settings App using ([[UIApplication sharedApplication] openURL: [NSURL URLWithString:UIApplicationOpenSettingsURLString]];)

This shall enable the user to directly navigate to the Watch companion app to setup my app for the watch.

I could not find any URL which would open the companion app in general or specific to a section of the companion app.

If direct linking is not supported, I am also interested in alternative approaches for this use case.

Thanks in advance!

EDIT: I checked the WatchKitSettings Info.plist file in the simulator to see if it registers any URL schema, but it does not.


回答1:


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.




回答2:


Previously, it was not possible to launch the WatchKit App from the iPhone app, but the iPhone app could be launched—only in the background—with the openParentApplication method.

As of WatchOS 2, however, it is now not possible for either app to cause the other to launch. Instead, there are new methods for queueing changes to be picked up when the other app is launched in the future.

One partial solution for your use case could be displaying a local notification which could be tapped to open the watch app. The primary flaw in such an approach is I do not believe there is a way to limit this notification to the Watch only, so it would also appear on the iPhone where if tapped it would bring the iPhone app to the foreground. Messy if implemented like this, and therefore not worth it I'd have thought, even if it could pass app store review.



来源:https://stackoverflow.com/questions/35055301/how-to-programmatically-open-apple-watch-companion-app-from-ios-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!