我正在開發一個使用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.");
}
}];
}
}];
請指導我改正我的錯誤..
然後會發生什麼 - >不發送推送,或只發送給錯誤的人?你檢查瞭解析控制檯嗎?返回的錯誤是什麼? – tomsoft
是的,我檢查它顯示推送發送0 – Ragul
,如果你嘗試從推控制檯執行相同的查詢,會發生什麼?問題可能在queryInstallation中,不是? – tomsoft