我正在尝试使用 Parse.com SDK 实现 iOS 推送通知。 问题是,有时没有任何错误日志就不会发送推送通知。我已将代码更改为:
- (IBAction)send:(id)sender {
PFQuery *usernameQuery = [PFUser query];
[usernameQuery whereKey:@"objectId" containedIn:self.recipients];
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"user" matchesQuery:usernameQuery];
PFPush *push =[[PFPush alloc] init];
[push setQuery:pushQuery];
[push setMessage:[NSString stringWithFormat:@"%@: %@", [PFUser currentUser].username, self.kwik]];
[push sendPushInBackground];
[self.navigationController popToRootViewControllerAnimated:YES];
NSLog(@"%p", push);
}
我不知道每次用户发送推送时分配的 PFPush 是否仍然会出现此问题。
在我将代码更改为这个代码之前,我正在调用 self.push = [[PFPush alloc] init];
在 viewDidLoad 方法中,因为我不喜欢每次用户因为内存使用而发送 Push-Notification 时分配一个新的 PFPush。
我现在的问题是:每次用户发送推送时分配一个新的 PFPush 对象是否重要,或者我可以在 viewDidLoad 方法中分配它吗?
最佳答案
行:
PFPush *push =[[PFPush alloc] init];
创建一个对象,但对它的引用是短暂的(完成异步推送请求所需的时间),在 ARC 项目中,代码将在编译时插入以释放它,因此无需担心内存分配。
您在获取推送发送时可能遇到不相关的问题。一种调试方法是使用 block variety of push in background called sendPushInBackgroundWithBlock 。这样您就可以检查错误是否已打开。
关于ios - 在 Objective-C 中解析推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31523771/