Reputation: 1762
I am using the newest version of the Parse iOS SKD (v1.4.2) and getting my app actually ready for iOS 8...
Now I came across the following problem:
If a user subscribes to a push channel I am using the saveInBackgroundWithBlock
method to show an alert after the subscription was successful.
The problem is now that the succeeded block is never been called!
The subscription it self woking without any problem - the new channel is showing up immediately at the Parse.com backend.
So I am really confused! ;)
Does anyone have the same problem and especially have a solution for it?
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation addUniqueObject:channel forKey:@"channels"];
[currentInstallation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
// Show success Alert
UIAlertView *successAlert = [[UIAlertView alloc] initWithTitle:@"Success" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[successAlert show];
} else {
// Show error Alert
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[errorAlert show];
}
}];
Update: I played around with it and have noticed that the block is called but my alert is not shown...
Upvotes: 0
Views: 501
Reputation: 611
Always check the succeeded
param. As with Apple APIs it's just a bit more save. This is how I would do it. Also since you are targeting iOS8 I strongly suggest using the new UIAlertController
API.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation addUniqueObject:channel forKey:@"channels"];
[currentInstallation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
NSLog(@"%@", [error localizedDescription]); // DEBUG
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController* alert;
if (succeeded && !error) {
// Success Alert
alert = [UIAlertController alertControllerWithTitle:@"Success"
message:nil
preferredStyle:UIAlertControllerStyleAlert];
} else {
// Error Alert
alert = [UIAlertController alertControllerWithTitle:@"Error"
message:nil
preferredStyle:UIAlertControllerStyleAlert];
}
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
});
}];
Upvotes: 1