ios - 在 Objective-C 中解析推送通知

标签 ios objective-c memory parse-platform push-notification

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

相关文章:

ios - UIFont:字体大小不同

ios - 在 UITableViewCell 中有一个 UITextField

ios - 返回上一个 WatchKit 接口(interface) Controller

c++ - cudaMemcpy 来托管设备分配的内存仍然不可能吗?

java - 在运行时更改堆栈大小

android - 我可以从哪里更改已在 App Store 中的应用程序的刷新率?

ios - 为什么删除而不是添加。plist

ios - 如何从导航栏中完全删除后退按钮?

ios - 如何避免 iOS 中的堆碎片

c++ - 在 C++ 中,类函数放在内存的哪个位置?