Unable to save channels to PFInstallation (iOS)

2020-05-03 11:17发布

问题:

I'm trying to add / remove channels from PFInstallation but I keep getting the same error message:

   Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Operation is invalid after previous operation.'

My code:

NSString * channel=[NSString stringWithFormat:@"%@%@%@", city, @"_", self.titleLabel.text];
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
if([sender isOn]){
    [currentInstallation addUniqueObject:channel forKey:@"channels"];
} else{
    [currentInstallation removeObject:channel forKey:@"channels"];
}
[currentInstallation saveInBackground];

回答1:

There is a bug in addUniqueObject method, when channels is nil. You should add this before it.

if (currentInstallation.channels == nil)
{
    currentInstallation.channels = [[NSArray alloc] init];
}

Also, you should use saveEventually instead of saveInBackGround.

This should be a bug in SDK.