如何以编程方式从iOS应用程序打开Apple Watch配套应用程序

时间:2021-11-29 13:03:05

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

我想向用户提示,我的iOS应用程序支持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]];)

所以我想在我的iOS应用程序中链接/打开Apple Watch配套应用程序,非常类似于使用([[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.

这将使用户能够直接导航到Watch配套应用程序以设置我的手表应用程序。

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

我找不到任何可以打开常用应用程序或特定于随播应用程序部分的URL的URL。

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.

编辑:我检查了模拟器中的WatchKitSettings Info.plist文件,看看它是否注册了任何URL模式,但事实并非如此。

2 个解决方案

#1


2  

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.

我想这是不可能以编程方式从iOS启动手表伴侣应用程序。相反的方式是可能的:在收到来自手表的消息后在后台启动iOS应用程序。请参阅WWDC talk介绍Watch Connectivity。

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

你可以检查WCSession.defaultSession()。watchAppInstalled并要求用户启动应用程序,如果它是真的。

#2


1  

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.

以前,无法从iPhone应用程序启动WatchKit应用程序,但iPhone应用程序只能在后台启动 - 使用openParentApplication方法。

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.

但是,从WatchOS 2开始,现在任何一个应用程序都无法启动另一个应用程序。相反,在将来启动其他应用程序时,会有一些新方法可以将更改排队。

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.

您的用例的一个部分解决方案可能是显示本地通知,可以点击该通知来打开手表应用程序。这种方法的主要缺陷是我不相信有一种方法可以将此通知仅限于Watch,因此它也会出现在iPhone上,如果点击它会将iPhone应用程序带到前台。凌乱,如果这样实施,因此不值得我,我想,即使它可以通过应用程序商店审查。

#1


2  

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.

我想这是不可能以编程方式从iOS启动手表伴侣应用程序。相反的方式是可能的:在收到来自手表的消息后在后台启动iOS应用程序。请参阅WWDC talk介绍Watch Connectivity。

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

你可以检查WCSession.defaultSession()。watchAppInstalled并要求用户启动应用程序,如果它是真的。

#2


1  

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.

以前,无法从iPhone应用程序启动WatchKit应用程序,但iPhone应用程序只能在后台启动 - 使用openParentApplication方法。

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.

但是,从WatchOS 2开始,现在任何一个应用程序都无法启动另一个应用程序。相反,在将来启动其他应用程序时,会有一些新方法可以将更改排队。

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.

您的用例的一个部分解决方案可能是显示本地通知,可以点击该通知来打开手表应用程序。这种方法的主要缺陷是我不相信有一种方法可以将此通知仅限于Watch,因此它也会出现在iPhone上,如果点击它会将iPhone应用程序带到前台。凌乱,如果这样实施,因此不值得我,我想,即使它可以通过应用程序商店审查。