在parsingios中更新安装表中的设备令牌

我想在使用iOSparsing上更新安装表中的设备令牌。 为了保存设备令牌,我做了:

 PFInstallation *currentInstallation = [PFInstallation currentInstallation]; [currentInstallation setDeviceTokenFromData:(NSData*)[AppHelper userDefaultsForKey:@"token"]]; [currentInstallation setObject:[PFUser currentUser].objectId forKey:@"user"]; NSArray *channels = [NSArray arrayWithObjects:@"AnyString",nil]; currentInstallation.channels=channels; [currentInstallation saveInBackground]; 

我想更新这个设备令牌。 我知道更新令牌,我必须使用其余的API,即https://api.parse.com/1/installations 。 如何更新行,因为我也没有安装ID。

请提供适当的语法。

在AppDelegate的didRegisterForRemoteNotificationsWithDeviceToken方法中写下面的代码。

 - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { PFInstallation *currnentInstallation = [PFInstallation currentInstallation]; [currnentInstallation setDeviceTokenFromData:deviceToken]; [currnentInstallation saveInBackground]; } 

对于频道中的注册用户,在login屏幕中使用以下代码

 PFInstallation *currentInstallation = [PFInstallation currentInstallation]; if ([PFUser currentUser].objectId) { currentInstallation[@"user"] = [PFUser currentUser]; currentInstallation.channels = @[[NSString stringWithFormat:@"user_%@",[PFUser currentUser].objectId]]; NSLog(@"Saving Installation channel = %@",currentInstallation.channels); [currentInstallation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { NSLog(@"Current installation updated: Error: %@",error); }]; } 

有关更多详细信息,请参阅此链接https://www.parse.com/docs/ios/guide#push-notifications-installations

AppDelegate's didRegisterForRemoteNotificationsWithDeviceToken方法中,将deviceToken设置为安装表并将设备标记保存到NSUserDefaults ,如下所示:

 PFInstallation *currentInstallation = [PFInstallation currentInstallation]; [currentInstallation setDeviceTokenFromData:deviceToken]; currentInstallation.channels = @[@"global"]; [currentInstallation saveInBackground]; [[NSUserDefaults standardUserDefaults]setObject:deviceToken forKey:@"deviceToken"]; 

并在login或注册,像这样设置用户:

 PFInstallation *currentInstallation = [PFInstallation currentInstallation]; [currentInstallation setObject:[PFUser currentUser] forKey:@"User"]; [currentInstallation setDeviceTokenFromData:[[NSUserDefaults standardUserDefaults] valueForKey:@"deviceToken"]]; currentInstallation.channels = @[@"global"]; [currentInstallation saveInBackground]; 

更新:

你需要添加安装表。 将列userID添加到安装,然后用当前用户的userID获取查询安装表。 你可以参考这个https://www.parse.com/questions/retrieve-objectid-from-installation-table链接以获得更好的理解
希望能帮助到你 :)