WatchOS应用程序4.0:如何安排本地通知

我的应用程序在后台或非活动模式,然后本地通知无效。 我从来没有收到当地的通知。

更新:less于3分钟安排本地通知它工作正常,但更多的3分钟,这是行不通的。 那么如何解决这个问题?

根据我的理解我的代码如下。

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); } }]; 

欣赏是否有任何build议或想法。

确保你的iphone被locking。 当涉及到通知时,它关于在哪里发送通知。

在模拟器上运行你的手表应用程序,从iPhone模拟器安排通知和lockingiPhone模拟器屏幕,保持手表模拟器活跃,在这种情况下,当通知被触发,它将在您的手表模拟器上交付。 当您将在实际设备上进行testing时也是如此 。 来源链接

而当iPhone和手表locking,首选是iPhone。

UPDATE

苹果手表的通知