My application is in the background or in inactive mode, then the local notification does not work. I never get a local notice on a watch.
Update: for less than 3 minutes, a local notification is assigned, which works fine, but for more than 3 minutes it does not work. so how to solve these problems?
As I understand it, my code is as follows.
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
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];
double timer = 15*60;
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:time
repeats:NO];
UNNotificationAction *snoozeAction = [UNNotificationAction actionWithIdentifier:@"Track"
title:@"Track" options:UNNotificationActionOptionForeground];
UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:@"UYLReminderCategory"
actions:@[snoozeAction] intentIdentifiers:@[]
options:UNNotificationCategoryOptionCustomDismissAction];
NSSet *categories = [NSSet setWithObject:category];
[center setNotificationCategories:categories];
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);
}
}];
Evaluate if there is any suggestion or idea.
source
share