- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    NSString *message = @"";
    id alert = [userInfo objectForKey:@"alert"];
    if ([alert isKindOfClass:[NSString class]]) {
        message = alert;
    } else if ([alert isKindOfClass:[NSDictionary class]]) {
        message = [alert objectForKey:@"body"];
    }
    NSLog(@"%@",message);
}
以上是我的源代码。
问题说明:我使用pushMeBary给我的应用发了一个推送信息,此时我的程序在真机上测试着,xcode中 调试确实进入了这个委托方法,可是我打印出来的message一直显示为null。我还以为程序运行着不可以,所以把message保存到本地,再次发送推送信息,收到了,打开真机上的文件,文件确实存在,但是没有任何内容。请问哪里有问题,仔细说明,谢谢!!
        NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
        NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"pushinfo.plist"];
        NSMutableArray *array;
        if ([[NSFileManager defaultManager] fileExistsAtPath:filePath] ) {
            array = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
            if (array.count == 0) {
                [array addObject:message];
            }
            else{
                [array insertObject:message atIndex:0];
            }
        }
        else{
            array = [[NSMutableArray alloc] init];
            [array addObject:message];
        }
        [array writeToFile:filePath atomically:YES];

解决方案 »

  1.   

    你使用pushMeBary时写这个alert了么?...
    另外,你是说pushMeBaby吗?给你个连接
    https://github.com/stefanhafeneger/PushMeBaby另外,给你推荐一个非常详细指南,可惜它是英文的
    http://mobiforge.com/developing/story/programming-apple-push-notification-services
      

  2.   


    哦,另外,为了确定你写了alert,我把payload的信息给你写出来
    {"aps":{"alert":"This is the alert message.","badge":1}}
      

  3.   

    你好,问题找到了,原来是我把aps搞丢了,所以如果直接在userInfo里找alert是找不到的,要先找到aps才可以,内容在aps里。
    仔细看了payload才看出问题的。