在解析ios中更新安装表中的设备令牌 [英] Update device token in installation table in parse ios
问题描述
我想使用iOS
在解析时更新安装表中的设备令牌.
要保存设备令牌,我做了:
I want to update device token in installation table on parse using iOS
.
To save a device token I did:
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];
我想更新此设备令牌.我知道要更新令牌,我必须使用rest API,即 https://api.parse.com/1/installations .如何更新该行,因为我也没有安装ID.
I want to update this device token. I know to update token I have to use rest API i.e. https://api.parse.com/1/installations. How to update the row as I also don't have installation id.
请提供正确的语法.
推荐答案
在AppDelegate的didRegisterForRemoteNotificationsWithDeviceToken方法中编写以下代码.
Write below code in didRegisterForRemoteNotificationsWithDeviceToken method in AppDelegate .
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
PFInstallation *currnentInstallation = [PFInstallation currentInstallation];
[currnentInstallation setDeviceTokenFromData:deviceToken];
[currnentInstallation saveInBackground];
}
对于频道中的注册用户,请在登录屏幕中使用以下代码
For Register user in channels use below code in Login Screen
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
For more details , refer this link https://www.parse.com/docs/ios/guide#push-notifications-installations
这篇关于在解析ios中更新安装表中的设备令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!