7

My application in background or inactive mode then local notification not work. I have never receive local notification on watch.

Update: less then 3 minutes schedule a local notification it's work fine but more then 3 minutes it's not work. so how to resolve this issues?

As per my understanding My code is as follows.

UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;

// Objective-C
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
content.title = [NSString localizedUserNotificationStringForKey:@"Remider!" arguments:nil];
content.body = [NSString localizedUserNotificationStringForKey:@"Your watch is out of range" arguments:nil];
content.sound = [UNNotificationSound defaultSound];

// Time
// 15 min
double timer = 15*60;
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:time
                                                                                                repeats:NO];
// Actions
UNNotificationAction *snoozeAction = [UNNotificationAction actionWithIdentifier:@"Track"
                                                                          title:@"Track" options:UNNotificationActionOptionForeground];

// Objective-C
UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:@"UYLReminderCategory"
                                                                          actions:@[snoozeAction] intentIdentifiers:@[]
                                                                          options:UNNotificationCategoryOptionCustomDismissAction];
NSSet *categories = [NSSet setWithObject:category];

// Objective-C
[center setNotificationCategories:categories];

// Objective-C
content.categoryIdentifier = @"UYLReminderCategory";

NSString *identifier = [self stringUUID];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier
                                                                      content:content trigger:trigger];

[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
    if (error != nil) {
        NSLog(@"Something went wrong: %@",error);
    }
}];

Appreciate if any suggestion or idea.

BuLB JoBs
  • 841
  • 4
  • 20

1 Answers1

1

Make sure your iphone is locked. When it comes to notification, its about preference where to deliver that notification.

Run your watch app on simulator, from iPhone simulator schedule the notification and lock the iPhone simulator screen, keep the watch simulator active, in that case when notification is triggered , it will be delivered on your watch simulator. Same will be the case when you will test on actual devices. Source Link

And when both iphone and watch is locked, preference is iphone.

UPDATE

Notification on Apple Watch

Muneeba
  • 1,756
  • 10
  • 11
  • I know this. i was tested on actual device and i did not receive schedule a local notification on watch device. – BuLB JoBs Nov 22 '17 at 11:10
  • i tested with 10 minutes interval and it worked. Make sure notification is being scheduled. If it is , then it must have delivered somewhere, if not on watch then it must be iphone. – Muneeba Nov 22 '17 at 12:25
  • I appreciate your work but i want this notification on watch app. any suggestion or idea for watch application? – BuLB JoBs Nov 24 '17 at 06:04
  • 1
    As i mentioned earlier, its about preference where to deliver notification and OS handles it. Details are mentioned in this link https://support.apple.com/en-us/HT204791. Try the customise notification option in my watch app. – Muneeba Nov 24 '17 at 06:14
  • I like your comment but My watch application in background or inactive mode then get local notification. also my devices are disconnected with my watch and then need notification so above link not useful for me. need more help if you know. – BuLB JoBs Nov 24 '17 at 06:23
  • Its clearly mentioned in there that "When your devices disconnect, your notifications go to your iPhone instead of your Apple Watch". If you want notification on watch even your devices are disconnected then its not possible. What you want to achieve is currently the limitation in apple watch case. – Muneeba Nov 24 '17 at 06:27
  • Yes i know apple limitation! but my client want this notification when iPhone and iWatch is pair but disconnected status then notification fire on watch app. – BuLB JoBs Nov 24 '17 at 06:38