2017-05-24 75 views
0

如果您从通知中心点击通知,您会在代码中获得通知信息,但如果用户无法点击该通知,并且只需点击主屏幕上的应用程序图标?当应用程序进入前台时获取待处理通知

例如,因为通知有效载荷还包含徽章属性。然后用户可以点击应用程序图标,因为徽章号码闪亮,但在这种情况下,您如何管理代码中的等待通知?

如果没有此方法,那么通知有效载荷中的badge属性有点无用,不是。因为如果用户点击带有徽章号码的图标,他预计会发生某种情况,但应用程序无法对待处理的通知执行任何操作,因此无法执行任何操作。要么?

+0

的[应用程序时,通过点击应用程序图标直接启动没有得到推送通知数据]可能的复制(https://stackoverflow.com/questions/33471064/push-notification-data-not-getting-when-app -launched-直接-通过单击应用内-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 
} 
相关问题