[英]How to send push notification to particular group members using parse?
我正在开发一个使用parse作为后端的社交消息应用程序。 当有人在群组中发短信时,我需要向群组成员发送推送通知。
我的代码是:
PFQuery* getMembers = [PFQuery queryWithClassName:@"Group"];
[getMembers whereKey:@"objectId" equalTo:groupId];
[getMembers includeKey:PF_RECENT_USER];
[getMembers findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
NSArray *ar = [[NSArray alloc]init];
ar=[[objects objectAtIndex:0]objectForKey:@"members"];
NSLog(@"members %@",ar);
PFQuery *queryInstallation = [PFInstallation query];
[queryInstallation whereKey:PF_INSTALLATION_USER matchesKey:PF_RECENT_USER inQuery:getMembers];
PFPush *push = [[PFPush alloc] init];
[push setQuery:queryInstallation];
//[push setMessage:text];
NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
text, @"alert",
@"ursound.caf", @"sound",
@"Increment", @"badge",
// @"Optionally a type was set", @"type",
nil];
[push setData:data];
[push sendPushInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
if (error != nil)
{
NSLog(@"SendPushNotification send error.");
}
}];
}
}];
请指导我纠正错误。
您可以通过创建频道将推送通知发送给gruop成员,然后将用户订阅到该频道。 然后,您可以将推送通知发送到特定频道。
访问https://parse.com/docs/ios/guide#push-notifications ,以获取有关创建频道和使用频道发送通知的更多帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.