1

I am receiving a push notification and trying to parse the dictionary as follows but I am getting the following exception.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull isEqualToString:]: unrecognized selector sent to instance 0x1a6574ef8'

Here is my received dictionary

enter image description here

Implementation

-(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"]];
        }
}
casillas
  • 16,351
  • 19
  • 115
  • 215

1 Answers1

1

You need also check for NSNull class, try with this

-(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"]];
            }
        }

    }
}

Hope this helps

Reinier Melian
  • 20,519
  • 3
  • 38
  • 55