2015-12-06 125 views
1

當應用程序關閉時,我需要檢測用戶何時從推送彈出視圖中打開我的應用程序。當應用程序關閉目標時,我的應用程序從推送通知中打開時檢測到。

我試試這個:

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

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

    } 
} 

但始終launchOptions回報爲零。

+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) 
    { 

    } 

} 
相關問題