How to launch a watchOS app from a notification? - ios

I've started to learn watchKit and watchOS.
After finding out how to handle notifications coming from a button set inside PushNotificationPayload.apns, I would like to set up my own notification that is going to fire at a given time, wake up the user with some kind of notification while the app is in the background, and possibly launch the app.
How can I do that?

In watchOS 2, this required scheduling the notification on the phone. It wasn't possible to wake up the watch app from the phone.
In watchOS 3, you can now use the new UserNotifications framework to schedule, deliver, and handle local notifications right on the watch.
You can display an actionable notification on the watch, which can open your watch app from the notification.
WWDC 2016 covered this material in two Introduction to Notifications and Quick Interaction Techniques for watchOS sessions.

Related

Will my 3rd party iOS app automatically send notifications to Apple Watch?

I'm creating an iOS application for the iPhone the has push notification abilities. If a user has an Apple watch and has notification mirroring on, will the Watch get the notification automatically, or would I need to develop a watch app as well so that they can pop up on it? The latter seems to make more sense based off of other notification models, but the way Apple talks about the notification functionality being automatic in their docs is throwing me off a little.
The watch will show a push notification even if you don't have a watch app, but you will get the default design and functionality.

Local Notifications in Apple Watch

How do you send Local Notifications from iPhone to an Apple Watch app when the Apple Watch app is in the background? And how do you check Local Notifications in the simulator, if possible?
The notifications shown at Apple Watch are the sames that appears in your iPhone.
If you have your iPhone locked, notifications go to the Apple Watch also.
You can not send a notification that only shows at Apple Watch.
As of Apple Docs:
Apple Watch takes full advantage of the existing interactive
notification support on iOS. If your iOS app supports notifications,
Apple Watch displays those notifications at appropriate times. When
one of your app’s local or remote notifications arrives on the user’s
iPhone, iOS decides whether to display that notification on the iPhone
or on the Apple Watch. For notifications sent to Apple Watch, the
system lets the user know subtly that a notification is available. If
the user chooses to view the notification, the system displays an
abbreviated version of the notification first, followed by a more
detailed version. The user can dismiss the detailed notification,
launch your Watch app, or act on the notification by tapping an
available action button.
Apps are not required to do anything to support notifications. The
system provides a default notification interface that displays the
alert message from the notification. However, apps can customize the
notification interface and include custom graphics, content, and
branding.

A way to selectively deliver UILocalNotifications to iPhone vs Apple Watch?

I'm trying to create a feature where certain UILocalNotifications trigger a sound despite the fact that they are displayed in an Apple Watch, or if that's not possible, are not routed at all to the Apple Watch and just to an iPhone where they can play a sound. Having the watch produce a sound is not ideal compared to the iPhone since I need it to overlay any music the user is playing on headphones.
Obviously the user can disable notifications on the Apple Watch for the app, but there are cases where it is useful to receive notifications on the Apple Watch and that is an all-or-nothing solution.
The Apple documentation states:
When one of your app’s local or remote notifications arrives on the user’s iPhone, iOS decides whether to display that notification on the iPhone or on the Apple Watch.
Is there any information on how iOS decides where to display a notification? Is there any programmatic way to disable notification forwarding to Apple Watch?
You can selectively disable notification in apple watch: http://www.imore.com/how-turn-alerts-apps-apple-watch
See the answer in below link for app’s local or remote notifications guide:
https://stackoverflow.com/a/33581623/2401116

Wakeup Watch app OS2 from the parent IOS app?

I would like to give a haptic feedback on the watch. That works fine as long as the watch app is active, but if the watch app goes in background the haptic feedback is not played. Is there a possibility to "wake up" the watch app from the parent IOS app to play the haptic feedback? (NOT A NOTIFICATION)
Since you prohibit Notifications, is not possible to do what you describe. Your watch app can act on messages from the iOS only when it starts up, resumes, or is currently loaded and running.
WatchConnectivity gives you 5 ways of sending data between the watch and phone.
sendMessage, sendMessageData: your scenario excludes these calls since both the watch and iPhone apps need to be active for this mechanism to work.
updateApplicationContext, transferUserData, and transferFile can be invoked from the iOS app at anytime, regardless of the state of your watch app. However, these messages are sent on a background thread and your watch app delegate will receive them the next time the watch app is loaded. By the design of the watch OS, none of these methods can trigger the watch app to load or become active.

Apple Watch Instant Notification

Is it possible to send instant notifications to Apple Watch from an iPhone app? The Apple Watch guide says "Apple Watch displays those notifications at appropriate times". So looks like there is no guarantee that the notification will be instant. I'm developing an iOS app that provides navigational notifications so those have to be instant.
Unfortunately WatchKit doesn't support it at this time. Not only can you not guarantee when the notification will appear, you can't even guarantee it will show up on the Watch. The OS decides which device is active and routes the notification there.
You can schedule/fire a local user notification to make it shown on the Watch, with limitations:
Users may turn off notifications of your app on Watch.
Notifications are only sent to Watch when the paired iPhone is locked, and the watch is on the wrist.

Resources