UIAlertView上的iOS分析通知消息(null)



我正在使用Parse.com向一个简单的iOS web视图应用程序发送推送通知,但我似乎无法让它显示我的JSON负载中的消息文本:

{
    "alert": "Push Message goes here.",
    "url": "http://www.google.com"
}

这是我的AppDelegate.m:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    NSString* notifURL = [userInfo objectForKey:@"url"];
    NSLog(@"Received Push Url: %@", notifURL);
    NSString* message = [userInfo objectForKey:@"alert"];
    NSLog(@"Received Message: %@", message);
    NSLog(@"UserInfo: %@", userInfo);
    if (application.applicationState == UIApplicationStateActive) {
        UIAlertView *alertPush = [[UIAlertView alloc]initWithTitle:@"My Webview App"
                                                       message:message
                                                      delegate:self
                                             cancelButtonTitle:@"View"
                                             otherButtonTitles:@"Cancel", nil];
        [alertPush show];
        [alertPush release];
        objc_setAssociatedObject(alertPush, &aURL, notifURL, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }
}

以下是我的日志返回的内容:

收到的推送Url:http://www.google.com

收到的消息:(空)

用户信息:{aps={alert="此处显示推送标题";};url="http://www.google.com";}

我是不是遗漏了什么?

如果格式化UserInfo,您会看到它有两个键apsurl。CCD_ 5具有值CCD_ 6,并且CCD_。这本字典有一个值为Push Title goes here的关键字alert

UserInfo: { 
           aps = { 
                   alert = "Push Title goes here";
           }; 
           url = "http://www.google.com"; 
}

因此,您需要通过以下方式提取:

NSString *message = userInfo[@"aps"][@"alert"];
//First extract the dictionary with key : aps
//then extract the string with key : alert

最新更新