当应用关闭目标c时,当我的应用从推送通知打开时检测到

时间:2015-12-06 12:05:47

标签: objective-c push-notification

当用户关闭时,我需要检测用户何时从推送弹出视图打开我的应用程序。

我试试这个:

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

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

    }
}

但总是launchOptions返回nil。

1 个答案:

答案 0 :(得分:0)

如果喜欢这个:

 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
{

   if (application.applicationState == UIApplicationStateActive)
   {
      NSLog(@"push Application State Active");
   }
   else if(application.applicationState == UIApplicationStateInactive ||    application.applicationState == UIApplicationStateBackground)
   {

   }

}