保存Parse PFInstallation对象时丢失的字段

时间:2014-11-01 17:56:49

标签: ios xcode parse-platform

我在应用程序中保存了一个PFInstallation对象:didFinishLaunchingWithOptions - 我要求用户提供推送权限或与deviceToken有关 - 我发现很多标准字段未被填充,包括:

  • appIdentifier
  • appVersion
  • appName
  • 徽章
  • parseVersion
  • timeZone

(这些列在数据浏览器中未定义,并且不显示在PFInstallation对象的NSLog上。)

  • deviceType 填充

我抓住并成功将deviceModel和deviceOS保存到两个自定义列。但我有点困惑的是为什么上面的列未被定义。

以下是代码:

[Parse setApplicationId:PARSE_APPID_DEV
              clientKey:PARSE_CLIENTKEY_DEV];

// record device model and OS
NSString *model = [self getDeviceModelAndNumber]; // via sys/utsname.h
NSString *sysVersion = [[UIDevice currentDevice] systemVersion];

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
PFUser *loggedUser = [PFUser currentUser];
if (loggedUser)
    [currentInstallation setObject:loggedUser forKey:@"user"];

[currentInstallation setObject:model forKey:@"deviceModel"];
[currentInstallation setObject:sysVersion forKey:@"deviceOS"];
NSLog(@"installation: %@", currentInstallation);
[currentInstallation saveInBackground];

这个项目是在Xcode 6中创建的。在Xcode 5中创建的另一个项目中,我基本上做了同样的事情,并且正在填充和保存列。

其他人遇到过这个吗?我已经谷歌搜索了相当多但没有找到解决方案。任何帮助非常感谢。

2 个答案:

答案 0 :(得分:9)

经过多次实验后,似乎(显着)将最后一行改为

[currentInstallation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    // some logging code here
}];

解决了这个问题。所以我想我应该向Parse提交一个错误。 (事实上​​,已经开放了一个:https://developers.facebook.com/bugs/712949858787516/

答案 1 :(得分:3)

这对我来说非常完美:

(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    // Store the deviceToken in the current installation and save it to Parse.

    PFInstallation *currentInstallation = [PFInstallation currentInstallation];
    [currentInstallation setDeviceTokenFromData:deviceToken];

    currentInstallation.channels = @[ @"YOU_CHANNEL_PREFERENCE" ];

    NSLog(@"currentInstallation %@", currentInstallation);

    // record device model and OS
    NSString *model = [[UIDevice currentDevice] model]; // deviceModel
    NSString *osVersion = [[UIDevice currentDevice] systemVersion]; // osVersion
    NSString *pushType = @"APN"; // pushType
    NSString *deviceName = [[UIDevice currentDevice] name]; // deviceName

    [currentInstallation setObject:model forKey:@"deviceModel"];
    [currentInstallation setObject:osVersion forKey:@"osVersion"];
    [currentInstallation setObject:pushType forKey:@"pushType"];
    [currentInstallation setObject:deviceName forKey:@"deviceName"];

    NSLog(@"installation: %@", currentInstallation);

    [currentInstallation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        // some logging code here
        NSLog(@"works");
    }];    
}