我在我的app委托文件中放置了以下代码。从理论上讲,它应该从推送通知中提取消息并将其显示在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];
}
答案 0 :(得分:6)
推送有效负载具有以下结构:
{
"aps" : {
"alert" : "Push notification text"
}
}
所以你需要拔出" aps"首先是字典,然后你可以检索" alert"的值。键:
pushText = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];