2017-05-24 45 views
0

通知センターから通知をタップすると通知情報が表示されますが、これをタップしないとホーム画面のアプリアイコンをタップするとどうなりますか?アプリがフォアグラウンドに入ったときに保留中の通知を取得

たとえば、通知ペイロードにバッジプロパティも含まれていたためです。バッジ番号が付いているので、ユーザーはアプリアイコンをタップできますが、この場合はコード内の待機中通知をどのように管理しますか?

この方法がない場合、通知ペイロードのバッジプロパティはビットが無駄です。そうではありません。ユーザーがバッジ番号でアイコンをタップすると、何か起こると予想されるため、アプリは保留中の通知で何もできないため、何かを行うことができます。または?

+0

[アプリはアプリのアイコンをクリックすることで直接起動時にプッシュ通知データを取得していない]の可能性のある重複(https://stackoverflow.com/questions/33471064/push-notification-data-not-getting-when-app -launcched-by-click-app-ic) – Bastian

答えて

1

getDeliveredNotificationsメソッドでこれが可能です。

- (void)applicationWillEnterForeground:(UIApplication *)application { 
    NSLog(@"msg applicationWillEnterForeground"); 
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 
    [[UNUserNotificationCenter currentNotificationCenter] getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> * _Nonnull notifications) { 
     NSLog(@"msg getDeliveredNotificationsWithCompletionHandler count %lu", [notifications count]); 

     for (UNNotification* notification in notifications) { 
      // do something with object 
      NSLog(@"msg noti %@", notification.request); 
     } 

    }]; 
#endif 
} 
関連する問題