gpt4 book ai didi

ios - 写入 PFInstallation

转载 作者:行者123 更新时间:2023-11-29 02:36:28 26 4
gpt4 key购买 nike

我正在尝试将 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com