Notification triggered from iPhone to Watch

Hi,


I have a test app for local iOS notifications but I want them to be displayed on the Apple Watch.

Is there a way to show a notification on the apple watch triggered from the iPhone app?

Maybe periodic or per button click.


Thanks

Replies

iOS seems to decide where your notification will be displayed. As far as I know you just schedule a notification as usual.

According to the documentation it will be shown on the watch if it's paired with the iPhone and the iPhone is locked at the moment of triggering.


Here is the swift code how I do it (based on a lot of code I've seen online):


let localNotification = UILocalNotification()


localNotification.alertTitle = "Hello"
localNotification.alertBody = "Hello, World!"
localNotification.category = "MyCategory"
localNotification.fireDate = NSDate() // this will trigger instantly, pass a future date to make it trigger in the future.


let application = UIApplication.sharedApplication()
application.scheduleLocalNotification(localNotification)


That's how I schedule notifications. As my notifications are ment for my Watch companion app, I schedule them by sending a message from the watch to iOS (via WCSession) and thus when the iOS receives a message of the correct type it will do something like the logic above.


However.... 😢

it seems to behave pretty odd for me. In my simulator it always gets shown on the iPhone, even when its locked and when I deploy it on real devices I just get not notification at all.


So not sure what's going on, hopefully somebody might give you a better answer then me.

I followed this example for local notifications: http://jamesonquave.com/blog/local-notifications-in-ios-8-with-swift-part-1/


If the iPhone is inactive and the Watch is activ the notifcations will be shown on the watch.

If both are inactive the notifications will be shown on the iPhone.


But what I need is an active iPhone where I press a button and a notifcation will popup on the inactive watch.

I now schedule these notifications via after iOS, triggered by a message by the WatchOS send via: https://developer.apple.com/library/prerelease/watchos/documentation/WatchConnectivity/Reference/WCSession_class/index.html#//apple_ref/occ/instm/WCSession/transferUserInfo:


In the documentation it says it guarantees that that dictionary will be delivered, so that seems to be fine.


Edit: That seems to not work at all, as now I don't receive any notifications by using that system. (This was because it only gets handled when the user starts the iOS App)


Edit 2: Moved back to Messages for notifications as it's important that these schedules happen immediatly. And according to the documentation it seems that it wakes up the iOS app in the background to make sure it happens. The only problem is t hat I still don't get notifications on real physical devices. The simulator however does work nice. I think this is a known issue? As I'm fairly sure I've seen similar complaints floating around.


Edit 3: Also made a stackoverflow, as this forum is pretty inactive as far as I can see: http://stackoverflow.com/questions/32052499/watch-os-2-0-beta-not-receiving-notifications

@Schleuma that's not possible. According to the documentation it's always iOS that's in control of where the notification will be shown. And as far as I know, when the iPhone is active it will be always shown on the iPhone.

notifications work on my real devices now.


have you tried to schedule the notifications a few seconds later (just for testing purposes)


let fireDate = NSDate().dateByAddingTimeInterval(NSTimeInterval(intValue))


I only get the notifications on the apple watch if I actually wear the watch and the iphone is locked. (which is ok for me)

Yeah I do exactly that, but I see this happening in my iOS Device backlog when the watch tries to send a message to the iOS device to schedule that notification. The problem doesn't appear to be the fact that notifications don't appear, but more that my watch can't seem to connect to the iOS device without getting rejected:


Aug 21 11:25:16 glendcs-iPhone apsd[100] <Notice>: (Note ) WatchKit: SPDeviceConnection, createXPCConnection, invalidationHandler 
Aug 21 11:25:16 glendcs-iPhone apsd[100] <Notice>: (Error) WatchKit: -[SPDeviceConnection activeComplicationsWithCompletion:] - error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.companionappd was invalidated from this process." UserInfo={NSDebugDescription=The connection to service named com.apple.companionappd was invalidated from this process.} 
Aug 21 11:25:16 glendcs-iPhone companionappd[113] <Notice>: (Error) WatchKit: <SPCompanionAppServer.m -[SPCompanionAppServer listener:shouldAcceptNewConnection:]:763> process 100 is not entitled, so rejecting connection


Edit: I resolved it by making sure the beta versions of my WatchOS2 and iOS9 were the same. Apperently my watch was still on B3, while my iPhone was already B5. Resolving that fixed it for me.