从配对的 Apple Watch 启动 iPhone 应用程序

Launching iPhone app from paired apple watch

我正在尝试实施一种变通方法,以从对应的 Apple Watch 应用程序打开我的 iPhone 应用程序。

这是我通过通知执行此操作的用例:

Watch displays an available deal with a CTA button to see details on Phone

--------------------------
New rates options published! 

check details on phone

<Button>
---------------------------

当用户选择手表上的按钮时,用户会收到本地通知 在配对 phone "Checkout your New Rate Options"

选择本地通知后,应用会启动并显示详细信息。

我的做法是:

**On watch:**

call *openParentApplication:reply:*    ...this will open the iOS app in the background

**On app:** 

In *application:handleWatchKitExtensionRequest:reply:* 
...which is called on the iOS app when opened in background, trigger a local notification 


**User:**

User picks the local notification to bring app to the foreground

这行得通吗?如果是这样,我如何在后台触发来自应用 运行 的即时本地通知?

最后一个问题:是否有一种(合法的)方法可以做到这一点而不需要本地通知(不会被应用商店拒绝)?

批准的方法是使用 WKInterfaceControllerHandoff instead of a local notification. With Handoff, you specify the current activity happening on your watch using the updateUserActivity:userInfo:webpageURL: 方法。然后,当用户查看 iPhone 的锁定屏幕时,他们会在左下角看到该应用程序的图标。从那里向上滑动将启动应用程序,Handoff activity 将在应用程序启动时传递到应用程序中,以便您可以适当地深入 link。

为此目的使用本地通知可能有效,但会有一些缺点。首先,它很笨重; Handoff 的方法更加被动。其次,为了安排本地通知,用户必须同意接收它们;从用户的角度来看,这是意外行为。

此外,请记住,在 watchOS 2 中,openParentApplication:reply: 方法不可用……真正的通信 API 已取而代之。查看 WatchOS 2 Transition Guide 了解更多信息,并查看 WatchConnectivity 框架。