ios - 写入 PFInstallation

标签 ios xcode parse-platform

我正在尝试将 BOOL 值写入 PFInstallation 中的列,但会不停地崩溃:

- (IBAction)pushSwitch:(id)sender {
NSUserDefaults *pushlocationStatus = [NSUserDefaults standardUserDefaults];

if (self.pushSwitch.on) {
    [pushlocationStatus setBool:YES forKey:@"pushlocationStatus"];

    PFQuery *query = [PFInstallation query];
    [query whereKey:@"objectId" equalTo:[PFInstallation currentInstallation].objectId];
    [query getFirstObjectInBackgroundWithBlock:^(PFObject *pushlocationObject, NSError *error) {
        pushlocationObject[@"locationPref"] = @YES;
        [pushlocationObject saveInBackground]; 
    }];
} else {
    [pushlocationStatus setBool:NO forKey:@"pushlocationStatus"];

    PFQuery *query = [PFInstallation query];
    [query whereKey:@"objectId" equalTo:[PFInstallation currentInstallation].objectId];
    [query getFirstObjectInBackgroundWithBlock:^(PFObject *pushlocationObject, NSError *error) {
        pushlocationObject[@"locationPref"] = @NO;
        [pushlocationObject saveInBackground];     
    }];
}
}

关于如何修复崩溃的任何建议:

我需要在 PFInstallation 中更新它,因为不是每个人都需要注册才能使用我的服务,但是,我希望能够不向这些选择不接收它的人发送推送。

最佳答案

好的。对于其他有同样问题的人,可以直接写入您的安装类,我从不怀疑这是一个问题,我仍然没有想出如何直接查询类,但现在要解决一个问题写入您的 Installation 类很简单......只是不要查询它,只需写入它即可。这是我用来修复我的 if 语句的方法:

- (IBAction)pushSwitch:(id)sender {
NSUserDefaults *pushlocationStatus = [NSUserDefaults standardUserDefaults];

if (self.pushSwitch.on) {
    [pushlocationStatus setBool:YES forKey:@"pushlocationStatus"];

    PFInstallation *installation = [PFInstallation currentInstallation];
    [installation setObject:@YES forKey:@"locationPref"];
    [installation saveInBackground];

} else {
    [pushlocationStatus setBool:NO forKey:@"pushlocationStatus"];

    PFInstallation *installation = [PFInstallation currentInstallation];
    [installation setObject:@NO forKey:@"locationPref"];
    [installation saveInBackground];
}
}

这只是一个例子。这对自定义分割的推送通知选项有很大帮助。

关于ios - 写入 PFInstallation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26308254/

相关文章:

iphone - 如何使用 UIWebView 加载一页又一页?

ios - 防止 "stacking"的 Sprite 节点相互重叠?

ios - 触摸并按住 TableViewCell 以显示(工具提示)弹出窗口在 iPhone 中是否可行?

ios - xcode 4.3 的无效断点

ios - 在多个 Xcode+PhoneGap 项目之间共享代码

ios - 如何找到有约束的 PFUser?

ios - SpriteKit : how to make SKEmitterNode particles twinkle?

ios - 从 Parse.com 检索字符串

ios - 使用 NSArray/PFQuery 中的数据填充表格 View 单元格

ios - 如何将 iOS 项目和字体大小缩放为屏幕大小