简体   繁体   English

在Objective-C中解析推送通知

[英]Parse Push Notification in Objective-C

I am trying to implement iOS Push-Notifications using the Parse.com SDK. 我正在尝试使用Parse.com SDK来实现iOS推送通知。 The problem is, that sometimes the Push Notification is not being sent without any error log. 问题是,有时没有任何错误日志就不会发送推送通知。 I have changed the code to this: 我将代码更改为此:

- (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);
}

I don't know if this problem is still happening with the PFPush being allocated everytime the user is sending a push. 我不知道每次用户发送推送时分配PFPush还是会出现此问题。 Before I have changed the code to this one, I was calling self.push = [[PFPush alloc] init]; 在将代码更改为该代码之前,我正在调用self.push = [[PFPush alloc] init]; in the viewDidLoad method, because I didn't like to allocate a new PFPush everytime the user is sending a Push-Notification because of memory usage. 在viewDidLoad方法中,因为由于内存占用,我不希望每次用户发送“推式通知”时都分配新的PFPush。 My question now is: Is it important to allocate a new PFPush object everytime the user sends a push or can I allocate it in the viewDidLoad method? 现在我的问题是:每次用户发送推送时分配一个新的PFPush对象是否重要?或者我可以在viewDidLoad方法中分配它吗?

The line: 该行:

PFPush *push =[[PFPush alloc] init];

creates an object, but references to it are short-lived (the time it takes to complete the asynch push request), and in an ARC project, code will be inserted at compile time to free it, so there's no need to worry about memory allocation. 创建一个对象,但是对它的引用是短暂的(完成异步请求请求所花费的时间),并且在ARC项目中,将在编译时插入代码以释放它,因此无需担心内存分配。

You may have an unrelated problem getting the push to send. 您可能有不相关的问题,无法发送推送。 One way to debug is to use the block variety of push in background called sendPushInBackgroundWithBlock . 一种调试方法是在后台使用称为sendPushInBackgroundWithBlock的各种块推送 With that you can check the error if there is on. 这样,您可以检查错误是否存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM