Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 摘录;“警惕”;推送通知中的文本_Ios_Objective C_Parse Platform_Apple Push Notifications - Fatal编程技术网

Ios 摘录;“警惕”;推送通知中的文本

Ios 摘录;“警惕”;推送通知中的文本,ios,objective-c,parse-platform,apple-push-notifications,Ios,Objective C,Parse Platform,Apple Push Notifications,我在我的应用程序代理文件中放置了以下代码。理论上,它应该从推送通知中提取消息,并将其显示在UIAlertview中,但它只显示标题和蜡烛按钮,而不显示其他内容。有人能看出我哪里出了问题吗 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [PFPush handlePush:userInfo]; pushText = [u

我在我的应用程序代理文件中放置了以下代码。理论上,它应该从推送通知中提取消息,并将其显示在
UIAlertview
中,但它只显示标题和蜡烛按钮,而不显示其他内容。有人能看出我哪里出了问题吗

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    [PFPush handlePush:userInfo];
    pushText = [userInfo objectForKey:@"alert"];
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:NSLocalizedString(@"News", "")
                          message:pushText
                          delegate:nil
                          cancelButtonTitle:@"Ok"
                          otherButtonTitles: nil];
    [alert show];
}

推送有效负载具有以下结构:

{
    "aps" : {
             "alert" : "Push notification text"
             }
}
因此,您需要先拉出“aps”字典,然后才能检索“alert”键的值:


如果你试着调试代码,你会在pushText中得到正确的值吗?不,它会显示为
null
我觉得你的代码很好。userInfo dict处理来自发送方的任何键值对,您是否从字典中提取正确的键?我相信parse在发送推送时可以将自定义userinfo dict作为参数发送,因此如果定义@“customBodyText”:@“这是我的消息”,例如,请确保在读取通知(接收通知)时,读取@“customBodyText”键。如果在该方法的第一行中输出userinfo,你得到的实际字符串是什么?这就成功了-非常感谢!
 pushText = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];