私のアプリケーションは、バックグラウンドまたは非アクティブモードでローカル通知が機能しません。私は時計で地元の通知を受け取ったことがない。WatchOS App 4.0:ローカル通知をスケジュールする方法
更新: 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);
}
}];
提案やアイデアがあれば気に入ってください。
私はこれを知っています。私は実際のデバイスでテストされ、私は腕時計のデバイスにローカル通知を受信しなかった。 –
私は10分間隔でテストし、それは働いた。通知がスケジュールされていることを確認してください。そうであれば、それはどこかで納品されているに違いない。もし時計でなければそれはiphoneでなければならない。 – Muneeba
あなたの仕事に感謝しますが、時計アプリでこの通知が必要です。ウォッチアプリケーションの提案や考え方は? –