我正在尝试将 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];
}];
} khác {
[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];
} khác {
[pushlocationStatus setBool:NO forKey:@"pushlocationStatus"];
PFInstallation *installation = [PFInstallation currentInstallation];
[installation setObject:@NO forKey:@"locationPref"];
[installation saveInBackground];
}
}
这只是一个例子。这对自定义分割的推送通知选项有很大帮助。
Tôi là một lập trình viên xuất sắc, rất giỏi!