1

我构建了启用背景模式的应用程序,并且应用程序获取的推送通知有效负载具有“内容可用”键。

此设置导致每次didReceiveRemoteNotification应用程序收到推送通知时都被调用,这意味着如果我在应用程序处于后台时收到 3 个推送通知 - 该函数将触发 3 次,并且其中的代码将在应用程序执行时执行applicationDidBecomeActive

我最大的问题是没有办法知道用户是否点击了推送系统警报或点击了应用程序图标以将应用程序从后台带入,因为无论用户的操作如何,didReceiveRemoteNotification都会触发。

有没有办法确定用户点击了系统警报?

这:http ://samwize.com/2015/08/07/how-to-handle-remote-notification-with-background-mode-enabled/ 和其他答案似乎没有帮助

4

1 回答 1

-1
For app is background push 
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if ( application.applicationState == UIApplicationStateInactive || application.applicationState == UIApplicationStateBackground  )
    {
         //opened from a push notification when the app was on background
    }
}

For app is terminate state

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    if (launchOptions != nil) {
         // Launched from push notification
         NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

    }
}
于 2017-03-14T17:43:39.527 回答