Reputation: 129
I have setup Local Notification as below :
-(void)startLocalNotification
{
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];
}
I received notification on iPhone Simulator. But it will not fired notification of watchkit app. I am using below method in NotificationController.m in watchkit extension -
- (void)didReceiveLocalNotification:(UILocalNotification *)localNotification withCompletion:(void (^)(WKUserNotificationInterfaceType))completionHandler
{
NSLog(@"Notification Received ..");
completionHandler(WKUserNotificationInterfaceTypeCustom);
}
Can anyone tell me why I am not receiving local notification in watchkit App.
Thanks in advance.
Upvotes: 3
Views: 4504
Reputation: 2741
See Apple Watch Programming Guide HERE
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.
So you don't need to worry about to send notification on Watch, iOS will do it for you.
Anyhow if you want to send notification on watch only you can use Darwin Notification Concepts, but keep in mind there are some limitations, you can check in the given link.
You can also use shared container for communication between App and extension.
Hope it will help you.
Upvotes: 4