2017-08-06 54 views
0

我收到一個推送通知,並試圖解析字典如下,但我得到以下異常。NSInvalidArgumentException,原因:' - [NSNull isEqualToString:]

***終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因是: ' - [NSNull isEqualToString:]:無法識別 選擇發送到實例0x1a6574ef8'

這是我收到的字典

enter image description here

實施

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{ 
    if (application.applicationState == UIApplicationStateActive) 
    { 
     // exception happens the following line 
     if([[userInfo objectForKey:@"aps"] objectForKey:@"alert"] != NULL && 
      [[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]isEqualToString:@"New Order!"]) 
     { 
      [[NSNotificationCenter defaultCenter] postNotificationName: @"newOrderNotificationMessage" object: [userInfo objectForKey:@"aps"]]; 
     } 
} 
+0

你的警戒值是NSNULL類 –

回答

2

您也需要檢查NSNull類,嘗試用這種

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{ 
    if (application.applicationState == UIApplicationStateActive) 
    { 
     // exception happens the following line 
     if([[userInfo objectForKey:@"aps"] objectForKey:@"alert"] != NULL && [[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] class] != [NSNull class]){ 
      if ([[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]isEqualToString:@"New Order!"]) 
      { 
       [[NSNotificationCenter defaultCenter] postNotificationName: @"newOrderNotificationMessage" object: [userInfo objectForKey:@"aps"]]; 
      } 
     } 

    } 
} 

希望這有助於

+0

任何想法https://stackoverflow.com/questions/45778103/排序陣列與 - 另一元件 – hotspring

相關問題