ios - 解析.com : saveInBackgroundWithBlock - block not called

标签 ios push-notification parse-platform

我正在使用最新版本的 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/

相关文章:

ios - 将数据上传到 Parse.com 时,UIAlertView 似乎卡住了应用程序

swift - 尝试使用 MongoDB 从解析服务器保存或检索数据时出现 "Server is started without SSL support"错误

iphone - 如何一次更改所有本地化的 Storyboard 文件?

ios - 我可以在 IOS 中的 View 之前插入 ScrollView 吗?

iphone - 从推送打开我的应用程序时执行哪个回调

android - 如何更改 PushNotification 的消息内容?

swift - 如何保存 Parse 对象的一个​​值而不覆盖整个对象?

ios - 未知错误 -1=ffffffffffffffff 命令/bin/sh 在 Jenkins 中失败,退出代码为 1

iOS 本地化 : Localize views dynamically without messing with the storyboard/nib strings files

ios - 如何在 AppDelegate 之外注册推送通知?