BuL*_*oBs 7 objective-c watch ios localnotification
我的应用程序处于后台或非活动模式,然后本地通知不起作 我从未收到过关于观看的本地通知.
更新:少于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);
}
}];
Run Code Online (Sandbox Code Playgroud)
感谢是否有任何建议或想法.
确保您的 iPhone 已锁定。当谈到通知时,它涉及到在哪里发送通知的偏好。
在模拟器上运行您的手表应用程序,从 iPhone 模拟器安排通知并锁定 iPhone 模拟器屏幕,保持手表模拟器处于活动状态,在这种情况下,当触发通知时,它将传递到您的手表模拟器上。当您在实际设备上进行测试时,情况也是如此。 来源链接
当 iphone 和手表都被锁定时,优先选择 iphone。
更新
| 归档时间: |
|
| 查看次数: |
595 次 |
| 最近记录: |