如何从 Apple Watch 启动 iOS 应用程序? [英] How to launch iOS App from Apple Watch?

查看:47
本文介绍了如何从 Apple Watch 启动 iOS 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从 Apple Watch 启动 iOS 应用程序?

Is there any way to launch the iOS App from Apple Watch?

编辑:- 尝试使用下面的两个 api 但不起作用:-

Edit:- Tried using both api below but doesn't work:-

Apple Watch 代码

Apple Watch Code

在 interfaceController.m 内部调用

Calling Inside interfaceController.m

+ (BOOL)openParentApplication:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo, NSError *error)) reply;    // launches containing iOS application on the phone. userInfo must be non-nil

iOS 代码

在 Appdelegate.m 内部调用

Calling Inside Appdelegate.m

- (void) application:(UIApplication *) application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply

推荐答案

答案其实很有趣.它是 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 应用程序从 Watch Extension 置于前台,如果它尚未被置于前台.这违反了苹果的政策.虽然您实际上可以在 iOS 模拟器中执行此操作,但 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.这是Handoff 编程指南.仔细阅读这两份文档后,您将确切了解 Handoff 系统的工作原理.

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.

这篇关于如何从 Apple Watch 启动 iOS 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆