Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fields missing when saving Parse PFInstallation object

I'm saving a PFInstallation object in application:didFinishLaunchingWithOptions -- I am not asking the user for push permissions or anything to do with a deviceToken -- and I'm finding many of the standard fields are being left unpopulated, including:

  • appIdentifier
  • appVersion
  • appName
  • badge
  • parseVersion
  • timeZone

(These columns are undefined in the data browser, and do not show on an NSLog of the PFInstallation object.)

  • deviceType does get populated

I am grabbing and successfully saving the deviceModel and deviceOS to two custom columns. But I'm a bit baffled as to why the above columns are being left undefined.

Here's the code:

[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];

This project was created in Xcode 6. In a different project, created in Xcode 5, I am doing essentially the same thing, and the columns are being populated and saved correctly.

Anyone else encounter this? I've Googled for it quite a bit but not found a solution. Any help much appreciated.

like image 882
wallace Avatar asked Jan 28 '26 16:01

wallace


2 Answers

After many experiments, it appears that (remarkably) changing the last line to

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

solves the problem. So I suppose I should file a bug with Parse. (In fact, there's already one open: https://developers.facebook.com/bugs/712949858787516/ )

like image 193
wallace Avatar answered Jan 31 '26 08:01

wallace


This completely works perfect for me:

(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");
    }];    
}
like image 36
Matheus Veloza Avatar answered Jan 31 '26 07:01

Matheus Veloza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!