我正在使用最新版本的 Parse iOS SKD (v1.4.2) 并让我的应用真正为 iOS 8 做好准备...
现在我遇到了以下问题:
如果用户订阅推送 channel ,我将使用 saveInBackgroundWithBlock
方法在订阅成功后显示警报。
现在的问题是,成功的 block 从未被调用过!
订阅自动唤醒没有任何问题 - 新 channel 立即显示在 Parse.com 后端。
所以我真的很困惑! ;)
有没有人遇到同样的问题,尤其是有解决方案?
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];
}
}];
更新:我尝试了一下,发现该 block 被调用,但我的警报没有显示...
最佳答案
始终检查 succeeded
参数。与 Apple API 一样,它只是更节省一点。我就是这样做的。此外,由于您的目标是 iOS8,我强烈建议您使用新的 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];
});
}];
关于ios - 解析.com : saveInBackgroundWithBlock - block not called,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26434367/