我想在使用 iOS
进行解析时更新安装表中的设备 token 。
为了保存我所做的设备 token :
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];
我想更新这个设备 token 。我知道要更新 token 我必须使用 rest 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];
}
要在 channel 中注册用户,请在登录屏幕中使用以下代码
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
关于ios - 在解析 ios 中更新安装表中的设备 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33053592/