且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从Apple Watch启动iOS App?

更新时间:2023-12-03 17:28:22

答案实际上非常有趣.是YESNO.

The answer is actually pretty interesting. It is YES and NO.

您可以通过openParentApplication:reply:方法在后台打开应用.如果终止或后台运行,则会在后台启动该应用程序.如果它已经在前台,它将直接调用该应用程序.

You CAN open the app in the background through the openParentApplication:reply: method. That will launch the app in the background if it is terminated or backgrounded. It will just call the app if it is already in the foreground.

您不能(如果尚未将iOS App从Watch Extension中带到前台).这违反了苹果的政策.尽管您实际上可以在iOS Simulator中完成此操作,但Apple已确认您无法在设备上执行此操作,也无法将解决方案提交给App Store.有关更多信息,请参见开发论坛上的文章.

You CANNOT bring the iOS App to the foreground from the Watch Extension if it is not already foregrounded. That is against Apple's policies. While you can actually do it in the iOS Simulator, Apple has confirmed that you cannot do this on the device or submit the solution to the App Store. See this article on the dev forums for more information.

如果您需要将iOS应用程序置于前台,那么目前可以部分执行此操作的唯一方法是使用Handoff API.这是

If you need to bring the iOS App to the foreground, the only way you can partially do this at the moment is to use the Handoff APIs. Here is another link to the Handoff Programming Guide. Once you read both of those documents carefully, you'll see exactly how the Handoff system works.

要实施,您需要在Watch Extension中添加WKInterfaceController updateUserActivity:userInfo:webpageURL:.然后,您需要在iOS应用中实现UIApplicationDelegate application:continueUserActivity:restorationHandler:.不幸的是,只有安装了Apple Watch,您才能测试该解决方案,但是文档明确指出将支持该解决方案.

To implement, you'll need to add the WKInterfaceController updateUserActivity:userInfo:webpageURL: in the Watch Extension. Then you'll need to implement the UIApplicationDelegate application:continueUserActivity:restorationHandler: in your iOS app. Unfortunately, you will not be able to test this solution until you have an Apple Watch, but the docs clearly state this will be supported.