ios - 在解析 ios 中更新安装表中的设备 token

标签 ios objective-c parse-platform ios9

我想在使用 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/

相关文章:

android - 使用按钮 appcelerator 推送通知(Android 和 iOS)

ios - 如何查找特定字符在 NSString 中以大写形式出现的次数?

ios - MFMailComposeViewController 在 iPad 上崩溃

iphone - 何时在 iPhone 上使用 UIView 与 UIViewController?

xcode - 解析 Facebook 登录失败,错误代码为 251

ios - 无法计算约束的确切值

ios - BLE 扫描未知服务

ios - 如何将sqlite文件导入ios中app的文档目录?

ios - 解析查询在只有一个对象时发现两个对象

ios - 在获取 PFQuery 对象时更新 View