从推送通知中提取“警报”文本
我有我的应用程序委托文件中放置以下代码。 理论上讲,它应该从推送通知中提取消息并在UIAlertview
显示 – 但是它会显示标题和蜡烛button,而不是其他任何东西。 有人可以看到我去哪里错了吗?
- (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 = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];