How to recreate deleted installation table at pars

2019-06-05 09:21发布

问题:

I accidentally dropped the Installation table in the parse.com data browser.

This table contained device data of my iOS users. With the device ID´s missing, i can´t send the users any push notifications.

The only way I know to recreate a installation row is to delete and reinstall the app. But this is no option because it totally breaks the user experience.

Is there a way to recreate the rows of the installations table from the objective C code?

Or anyway access the installationID and deviceToken, in that case so I would recreate the table per hand.

回答1:

As all other methods did not work, i updated my app in a way that saves all data of the currentInstallation in a backup table.

PFObject *backupInstallation = [PFObject objectWithClassName:@"installationRecovery"];
for (NSString *key in [PFInstallation currentInstallation].allKeys) {
    // Filter out the basic keys.
    if (![@[@"objectId", @"createdAt", @"updatedAt"] containsObject:key]) {
        [backupInstallation setObject:[PFInstallation currentInstallation][key] forKey:key];
    }
}
[backupInstallation saveInBackground];

After i got all installation entries, i manually added the missing ones to the Installation table. Although the objectId´s did not match the ones in the local entries, i got the push notifications to work.

You can also handle the copy job by writing a cloud function that does it for you. This could be triggered in a post save hook of installationRecovery.

I also made shure that this code only executes once on update. By checking a user default setting.

NSString *backuppedInstallation = [[NSUserDefaults standardUserDefaults] boolForKey:@"backuppedInstallation"];
if (!backuppedInstallation) {
    // Your code here
    [[NSUserDefaults standardUserDefaults] setBool:@(YES) forKey:@"backuppedInstallation"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}