我收到了推送通知,并试图按下面的方式解析字典,但我得到了以下异常。
*由于“NSInvalidArgumentException”异常终止应用程序,原因:'-NSNull isEqualToString::未识别的选择器发送到实例0x1a6574ef8‘
这是我收到的字典

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"]];
}
}发布于 2017-08-06 08:12:03
您还需要检查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"]];
}
}
}
}希望这能有所帮助
https://stackoverflow.com/questions/45529936
复制相似问题