気の利いたチェックで自分で修正できました...
基本的に、この全体の鍵は
-(void)applicationDidEnterBackground:(UIApplication *)application;
このメソッドは、アプリの高速切り替え (またはコントロール センター) に入ったときに呼び出されないため、それに基づいてチェックをセットアップする必要があります。
@property BOOL isInBackground;
@property (nonatomic, retain) NSMutableArray *queuedNotifications;
そして、通知を受け取ると...
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UIApplicationState appState = application.applicationState;
// Check if we're in this special state. If so, queue the message up
if (appState == UIApplicationStateInactive && !self.isInBackground) {
// This is a special case in which we're in fast app switching or control center
if (!self.queuedNotifications) {
self.queuedNotifications = [NSMutableArray array];
}
// Queue this to show when we come back
[self.queuedNotifications addObject:userInfo];
}
}
そして、私たちが戻ってくると...
- (void)applicationDidBecomeActive:(UIApplication *)application {
application.applicationIconBadgeNumber = 0;
if (!self.isInBackground) {
// Show your notifications here
// Then make sure to reset your array of queued notifications
self.queuedNotifications = [NSMutableArray array];
}
}
もう 1 つ実行したいことは、アプリの高速切り替えに移動し、ユーザーが別の場所に移動するというこの特殊なケースを確認することです。isInBackground BOOL を設定する直前にこれを行います。それらをローカル通知として送信することを選択します
-(void)applicationDidEnterBackground:(UIApplication *)application {
for (NSDictionary *eachNotification in self.queuedNotifications) {
UILocalNotification *notification = [self convertUserInfoToLocalNotification:eachNotification];
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
self.queuedNotifications = [NSMutableArray array];
self.isInBackground = YES;
}