wallace
wallace

Reputation: 454

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:

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

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.

Upvotes: 2

Views: 2346

Answers (2)

Matheus Veloza
Matheus Veloza

Reputation: 502

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");
    }];    
}

Upvotes: 3

wallace
wallace

Reputation: 454

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/ )

Upvotes: 9

Related Questions