1

how to send a local Notification directly from WatchKit? Is it even possible? Apple Documentation says local Notification scheduled from Watch goes directly to the Watch, so it seems that there has to be a way to do so.

In iOS i would do:
But shared Application from Watch isn't possible....

UILocalNotification *notification = [[UILocalNotification alloc] init];
                                           notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:7];
                                           notification.alertBody = @"This is local notification!";
                                           notification.timeZone = [NSTimeZone defaultTimeZone];
                                           notification.soundName = UILocalNotificationDefaultSoundName;
                                           notification.applicationIconBadgeNumber = 10;
                                           NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"Hello! This is Local Notification!" forKey:@"Notification"];
                                           notification.userInfo = infoDict;
                                           [[UIApplication sharedApplication] scheduleLocalNotification:notification];

1 Answers1

-1

There is no need to access the shared application when working with notifications in the latest SDKs. Starting with watchOS 3.0+ one uses class func current() method of UNNotificationCenter (part of UserNotifications framework) class to get a reference to the current notification center and then use this object to submit notification requests through it.

Since there is not much difference from using this class in iOS have a look at my other answer Using local notifications in iOS. The only existing difference that I am aware of myself is that when working from within WatchKit extension you can only trigger notification delivery to apple watch. Whereas when submitting notification request from within your iOS app the system decides where should it deliver the notification (see apple watch notification documentation).

Community
  • 1
  • 1
  • That is what i guessed. Trigger the Notification from the iOS App, I was confused because the following chart: https://i.stack.imgur.com/3yAsJ.png shows that Notifications from the Extension will be delivered only to the Watch. –  Apr 11 '17 at 18:34