在ios中推送通知问题

时间:2014-12-22 05:34:52

标签: ios push-notification

嗨,我是推送通知的新手,我正在开发一个项目,推送通知已被使用, 我理解所有代码,但不是[[userInfo objectForKey:@“payload”] objectForKey:@“userId”]],它可以在userinfo中存储值??

- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary*) userInfo {
**if ([self.profileManager.profile.userId isEqualToString:[[userInfo objectForKey:@"payload"] objectForKey:@"userId"]]**) {
    if (application.applicationState == UIApplicationStateActive) {
        UIRemoteNotificationType apnsType = [application enabledRemoteNotificationTypes];   
        if(apnsType != UIRemoteNotificationTypeNone) {
            if((apnsType & UIRemoteNotificationTypeAlert) != 0) {
                [self showNotificationAlert:userInfo];
            }

            if((apnsType & UIRemoteNotificationTypeBadge) != 0) {
                NSString* badge = [userInfo valueForKey:@"badge"];  
                application.applicationIconBadgeNumber = [badge intValue];
            }
        }
    } else {
        NSString* event = [[userInfo objectForKey:@"payload"] objectForKey:@"event"];
        if ([event isEqualToString:@"QUESTION_ANSWERED"]) {
            [self presentYouAsked];
        } else if ([event isEqualToString:@"QUESTION_ASKED"]) {
            [self presentFriendsAsked];
        }
    }
 }
}

1 个答案:

答案 0 :(得分:1)

userInfo字典是收到的推送通知数据的一部分。您引用的行提取另一个字典,与密钥"有效负载"相关联。从推送通知字典中,然后查找与密钥相关的值" userid"在那本字典中。

猜测"如果"声明它确定收到的推送通知是否适用于此设备上的当前用户。