Extract “alert” text from push notification

大兔子大兔子 提交于 2019-12-10 11:08:48

问题


I have the following code placed in my app delegate file. In theory, it should be extracting the message from the push notification and displaying it in a UIAlertview - yet it displays the title and the candle button, and nothing else. Can anybody see where I am going wrong?

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

回答1:


The push payload has the following structure:

{
    "aps" : {
             "alert" : "Push notification text"
             }
}

So you need to pull out the "aps" dictionary first and then you can retrieve the value for the "alert" key:

 pushText = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];


来源:https://stackoverflow.com/questions/27115054/extract-alert-text-from-push-notification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!