我使用解析sdk向特定用户发送推送通知? 问题是,如果接收方用户的应用程序在发送通知时正在运行,那么它工作正常,但如果接收方应用程序在发送推送通知时没有运行,则它不会收到任何推送徽章或警报。我做错了什么?请参阅代码.PFQuery * pushQuery = [PFInstallation query];
[pushQuery whereKey:Key_UserName equalTo:self.selectedBuddy.userName];
PFObject *object = [PFObject objectWithClassName:ClassName_Message];
object[Message_MessageText] = txtFieldMessage.text;
object[Message_SenderName] = applicationDelegate.userInfo.userName;
object[Message_ReceiverName] = self.selectedBuddy.userName;
[object saveInBackground];
NSDictionary *data = @{
Message_MessageText : txtFieldMessage.text,
Message_SenderName : applicationDelegate.userInfo.userName,
Message_ReceiverName : self.selectedBuddy.userName
};
// Send push notification to query
PFPush *push = [[PFPush alloc] init];
[push setQuery:pushQuery]; // Set our Installation query
[push setData:data];
[push sendPushInBackground];
`
答案 0 :(得分:0)
我认为问题是你没有正确设置推送查询,你需要查询安装..
需要这样的设置:
PFQuery *usernameQuery = [PFUser query];
[usernameQuery whereKey:@"username" equalTo:aName];
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"user" matchesQuery:usernameQuery];
您还必须确保在安装中有一个用户名字段,即每次用户登录时都需要:
PFInstallation *installation = [PFInstallation currentInstallation];
installation[@"user"] = [PFUser currentUser];
[installation saveInBackground];
也可能是您的数据字典中没有“警报”的问题。如果您希望推送正常工作,我认为这是必需的密钥,请尝试:
NSDictionary *data = @{@"alert": txtFieldMessage.text, Message_SenderName : applicationDelegate.userInfo.userName, Message_ReceiverName : self.selectedBuddy.userName, @"sound": @“”};