2016-05-17 15 views
0

我從服務器發送推送通知,如果應用程序在後臺運行,通知到達並點擊它調用didReceiveRemoteNotification()。爲什麼我會通過launchOption字典獲得Apple推送通知nil?

但是,當我殺了我的應用程序(後按兩下home鍵向上滑動的應用程序,通知到達但攻通知僅僅是直接在屏幕到App家裏,我已經編碼在didFinishLaunchingWithOptions:。launchOptions()像下面

if (launchOptions != nil) 
    { 
     NSDictionary* dictionary = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]; 
     if (dictionary != nil) 
     { 

      NSLog(@"Launched from push notification: %@", dictionary); 

      NSString *strVendId=[dictionary valueForKeyPath:@"payload.vendor_id"]; 

      UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
      UINavigationController *navController = (UINavigationController *)self.window.rootViewController; 

      VenderDetailController *vDetail=[mainstoryboard instantiateViewControllerWithIdentifier:@"venDetail"]; 
      vDetail.strVendorId=strVendId; 
      [navController pushViewController:vDetail animated:YES]; 
     } 
    } 

沒有辦法,我可以調試這是應用程序就會被殺死。也許我得到零字典我不知道。我甚至試圖刪除launchOption零條件,仍然沒有任何幫助。

我使用的目標C而這個問題正在讓我發瘋。

+0

你可以登錄launchOptions並告訴值 – Shubhank

+0

如何實現,如果我殺了應用程序,xcode項目停止。那麼我怎麼能在設備上記錄什麼? –

回答

2

首先檢查日誌在設備日誌以確認字典是零或不是。用於在應用程序終止時檢查日誌。轉到窗口 - >設備,然後選擇您的設備,然後點擊左下角的箭頭圖標,如下圖所示。您將可以看到,即使你不從Xcode中運行的應用程序的所有日誌:enter image description here enter image description here

登錄你所得到的字典,它會在調試問題。

1

嘗試......

所有的
NSDictionary *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 
1

您可以使用Chandan005的解決方案來查看調試控制檯,或者您可以使用didFinishLaunchingWithOptions:launchOptions中的UIAlertView來顯示dictionary內容,以檢查您是否獲得正確的遠程通知負載。