I am developing a social messaging app using parse as a backend. I need to send push notification to the group members when someone texted in the group.
My code is:
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.");
}
}];
}
}];
Kindly guide me to correct my mistake.
You can send push notification to gruop members by creating channel and then subscribe the user to that channel . Then you can send push notification to particular channel.
Visit https://parse.com/docs/ios/guide#push-notifications for more help for creating channel and send notification using channel.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.