且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当我尝试登录注册用户并通过解析启用推送通知时,我的应用程序崩溃

更新时间:2022-04-25 21:11:55

您仍然可以在没有当前用户的情况下注册安装,但您必须确保从注册中删除该用户 -

You can still register an installation without a current user, but you have to make sure that the user is removed from the registration -

- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    // Store the deviceToken in the current installation and save it to Parse.
    PFInstallation *currentInstallation = [PFInstallation currentInstallation];
    if ([PFUser currentUser] != nil)
    {
        currentInstallation[@"currentUser"]=[PFUser currentUser];
    }
    else {
        [currentInstallation removeObjectForKey:@"currentUser"];
    }
    [currentInstallation setDeviceTokenFromData:deviceToken];
    [currentInstallation saveInBackground];
}

然后,无论您在何处处理登录/注销事件,都可以更新当前的安装记录.例如 -

Then, wherever you handle login/logout events you can update the current installation record. For example -

-(void) loggedIn
{  

    PFInstallation *currentInstallation=[PFInstallation currentInstallation];
    currentInstallation[@"currentUser"]=[PFUser currentUser];
    [currentInstallation saveInBackground];

}

-(void) notLoggedIn
{

    PFInstallation *currentInstallation=[PFInstallation currentInstallation];
    [currentInstallation removeObjectForKey:@"currentUser"];
    [currentInstallation saveInBackground];

}