das*_*ist 1 iphone ios parse-platform
基于使用高级定位推送通知的解析指南,我理解为了PFInstallations与当前用户关联,应该通过以下方式:
PFInstallation *installation = [PFInstallation currentInstallation];
installation[@"user"] = [PFUser currentUser];
[installation saveInBackground];
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何能够"在运行中"为其他用户(即不是当前用户)做到这一点.例如,我有一个Message对象,我想发送给用户Sally,Alex和Ben:如何能够根据用户objectIds获得这些用户的PFInstallations,然后设置他们的PFInstallation,以便
//Sally, Alex and Ben's PFInstallations:
[installation setObject:YES forKey:message.objectId];
Run Code Online (Sandbox Code Playgroud)
...所以当我发出消息时,只有Sally,Alex和Ben会收到推送通知他们收到了我的消息?
谢谢!
这是我设法做到的方式.请注意,这recipientIDs是我发送推送通知的用户列表(确切地说是用户objectIds).
if (recipientIDs.count > 0){
//Find the users that were just sent the message
PFQuery *userQuery = [PFUser query];
[userQuery whereKey:@"objectId" containedIn:recipientIDs];
//Find the devices associated with these users
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"user" matchesQuery:userQuery];
//Send push to these users
PFPush *push = [[PFPush alloc] init];
NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@"New message from %@", [PFUser currentUser].username], @"alert",
@"Increment", @"badge",
nil];
[push setQuery:pushQuery]; // Set our Installation query
[push setData:data];
[push sendPushInBackground];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2113 次 |
| 最近记录: |