アプリでローカル通知を使用して、緊急メッセージをユーザーに警告しています。ユーザーがプッシュ通知を受信すると、ローカル通知が作成され、60 秒後に 60 秒間隔で起動されます。これはうまく機能し、緊急通知は予想どおり 60 秒ごとに発生します。
問題は、約 20 分後にローカル通知が停止することです。これは常に発生するわけではなく、通知が何時間も問題なく発生することがあります。ただし、この問題は頻繁に発生するようです。
iOS 9 ではこの問題はまったく発生せず、通知は一晩中繰り返し発生するので、これは iOS 10 に関連しているのではないかと考えています。
また、おそらくこれは OS からのメモリ不足に関係しているという予感がありますか? xCodeにアタッチしてデバッグすると、問題はまったく発生せず、無限に発生します。
通知を作成するために使用するコードは次のとおりです。
[[UNUserNotificationCenter currentNotificationCenter] getPendingNotificationRequestsWithCompletionHandler:^(NSArray<UNNotificationRequest *> * _Nonnull requests) {
dispatch_async(dispatch_get_main_queue(), ^{
//If notification already exists then kill it with fire
[self removeAllLocalNotifications];
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = @"Urgent";
content.sound = [UNNotificationSound soundNamed:@"dingdingding.wav"];
content.categoryIdentifier = @"urgentCategoryId";
content.body = @"You have an urgent message.";
// Deliver the notification in scheduled amount of seconds.
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:60 repeats:YES];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"urgentMessageId" content:content trigger:trigger];
// Schedule the notification.
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
NSLog(@"Notification creation Error");
}
if (completionHandler) {
completionHandler(UIBackgroundFetchResultNewData);
}
});
}];
});
}];
これは非常にイライラする問題であるため、どんな助けも大歓迎です。