Reputation: 638
I am trying to implement a workaround to open my iPhone app from its Apple Watch app counterpart.
Here is my use case for doing this with a notification:
Watch displays an available deal with a CTA button to see details on Phone
--------------------------
New rates options published!
check details on phone
<Button>
---------------------------
When the user picks the button on the watch, the user gets a local-notification on the paired phone "Checkout your New Rate Options"
On picking the local notification, the app is launched showing details.
My approach is:
**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
Will this work? If so how do I trigger an immediate local notification from the app running in the background?
Final question: is there a (legal) way to do this without the need for the local notification (one that will not get rejected by the app store)?
Upvotes: 0
Views: 294
Reputation: 3554
The approved way of doing this would be to use Handoff instead of a local notification. With Handoff, you specify the current activity happening on your watch using the updateUserActivity:userInfo:webpageURL:
method of WKInterfaceController
. Then, when the user looks at the iPhone's lock screen they'll see the app's icon in the bottom left corner. Swiping up from there will launch the application, and the Handoff activity will be passed into the app as it launches so that you can deep-link as appropriate.
Using local notifications for this purpose might work, but it would have some drawbacks. First, it's heavy-handed; Handoff is more passive in its approach. Second, in order to schedule a local notification, the user will have to agree to receive them; this is unexpected behavior from the user's standpoint.
Also, bear in mind that in watchOS 2, the openParentApplication:reply:
method is not available... a genuine communication API has taken its place. Check the WatchOS 2 Transition Guide for more info, and take a look at the WatchConnectivity framework.
Upvotes: 3