问题描述
有什么方法可以从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代码
调用Inside Appdelegate.m
Calling Inside Appdelegate.m
- (void) application:(UIApplication *) application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply
推荐答案
答案实际上非常有趣.是YES
和NO
.
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.这是.仔细阅读这两个文档后,您将确切了解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 App?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!