如何从Apple Watch启动iOS App?

时间:2021-03-16 01:22:31

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

有没有办法从Apple Watch推出iOS应用程序?

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

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

Apple Watch Code

Apple Watch Code

Calling Inside interfaceController.m

调用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 Code

iOS代码

Calling Inside Appdelegate.m

在Appdelegate.m内部调用

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

1 个解决方案

#1


19  

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

答案其实非常有趣。是和否。

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.

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

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应用程序从Watch Extension带到前台。这违反了苹果的政策。虽然您可以在iOS模拟器中实际执行此操作,但Apple已确认您无法在设备上执行此操作或将解决方案提交到App Store。有关更多信息,请参阅dev论坛上的这篇文章。

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.

如果您需要将iOS App置于前台,那么目前可以部分执行此操作的唯一方法是使用Handoff API。这是Handoff Programming Guide的另一个链接。一旦仔细阅读了这两个文档,您就会清楚地看到Handoff系统的工作原理。

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.

要实现,您需要在Watch Extension中添加WKInterfaceController updateUserActivity:userInfo:webpageURL:。然后,您需要在iOS应用程序中实现UIApplicationDelegate应用程序:continueUserActivity:restorationHandler:不幸的是,在您拥有Apple Watch之前,您将无法测试此解决方案,但文档明确指出这将得到支持。

#1


19  

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

答案其实非常有趣。是和否。

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.

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

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应用程序从Watch Extension带到前台。这违反了苹果的政策。虽然您可以在iOS模拟器中实际执行此操作,但Apple已确认您无法在设备上执行此操作或将解决方案提交到App Store。有关更多信息,请参阅dev论坛上的这篇文章。

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.

如果您需要将iOS App置于前台,那么目前可以部分执行此操作的唯一方法是使用Handoff API。这是Handoff Programming Guide的另一个链接。一旦仔细阅读了这两个文档,您就会清楚地看到Handoff系统的工作原理。

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.

要实现,您需要在Watch Extension中添加WKInterfaceController updateUserActivity:userInfo:webpageURL:。然后,您需要在iOS应用程序中实现UIApplicationDelegate应用程序:continueUserActivity:restorationHandler:不幸的是,在您拥有Apple Watch之前,您将无法测试此解决方案,但文档明确指出这将得到支持。