gpt4 book ai didi

ios - 解析 : Sending push notication to a user

转载 作者:行者123 更新时间:2023-11-28 19:01:35 28 4
gpt4 key购买 nike

我正在尝试向用户或所有用户列表发送推送通知。我可以使用以下代码段在 iOS 设备上成功发送(和接收):

// Create our Installation query
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"deviceType" equalTo:@"ios"];

// Send push notification to query
[PFPush sendPushMessageToQueryInBackground:pushQuery
withMessage:@"Hello World!"];

但是这段代码不起作用:

PFQuery *userQuery = [PFUser query];
NSLog(@"findObjects: %@",[userQuery findObjects]);

[userQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
NSLog(@"findObjectsInBackgroundWithBlock error: %@", error);
NSLog(@"findObjectsInBackgroundWithBlock objects: %@", objects); //this log indicated I do have one user named "user name"
}];

PFQuery *pushQuery = [PFInstallation query];
// [pushQuery whereKey:@"user" matchesQuery:userQuery];
[pushQuery whereKey:@"username" containsString:@"user name"]; //neither one of these works


// Send push notification to query
[PFPush sendPushMessageToQueryInBackground:pushQuery
withMessage:@"for you only"];

在 parse.com 网站的推送通知仪表板上,它的状态为“完成”,但订阅者为 0。

有什么建议吗?

编辑:来自 Parse 仪表板的更多详细信息:

enter image description here

最佳答案

您必须像现在一样使用 PFUser 查询来查询您的用户。一旦找到您要向其发送推送的用户,您就必须使用该“PFUser 对象”来执行安装查询。 (您应该使用整个 PFUser 对象作为安装查询的键)

如果您想向一组用户发送推送,您必须设置 Parse 的“分割”并将用户分配到该分割。阅读 Parse iOS 推送文档 https://parse.com/docs/push_guide#top/iOS

这是向单个用户发送推送的示例:

PFQuery *qry = [PFUser query];
[qry getObjectWithId: THE USERS OBJECT ID HERE ];

PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"user" matchesQuery:qry];

// Send push notification to query
PFPush *push = [[PFPush alloc] init];
[push setQuery:pushQuery]; // Set our Installation query
NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
@"A New Push Message was Put HERE!", @"alert",
@"ursound.caf", @"sound",
@"Increment", @"badge",
@"Optionally a type was set", @"type",
nil];
[push setData:data];


[push sendPushInBackground];

编辑 - 哦,假设我示例中的那些初始查询已经在后台任务中 -> 使用 getObjectInBackgroundWithId:^(bla bla.. ) 如果不在后台任务中运行它。

关于ios - 解析 : Sending push notication to a user,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24642671/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com