向查询中的所有用户发送推送通知

编程入门 行业动态 更新时间:2024-10-25 08:18:10
本文介绍了向查询中的所有用户发送推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在创建一个使用 Parse 云的应用程序.我正在尝试从用户向所有其他人发送消息.在文本字段中写入消息并按下发送后,委托调用以下方法并按如下所示处理推送:

I am creating an app that uses Parse cloud. I am trying to send a message from a user to all others. After writing the message in a textfield and pressing send, the delegate calls the following method and the push is handled as shown below:

- (BOOL)textFieldShouldReturn:(UITextField *)textField { //hide keyboard [textField resignFirstResponder]; NSString *message = self.broadcastText.text; //create a user query PFQuery *query = [PFUser query]; PFUser *current = [PFUser currentUser]; NSString *currentUsername = current[@"username"]; [query whereKey:@"username" notEqualTo:currentUsername]; //send push in background PFPush *push = [[PFPush alloc] init]; [push setQuery:query]; [push setMessage:message]; [push sendPushInBackground]; //clear text field textField.text = @""; return YES;}

发生的事情是,当我发送消息时,发件人(在本例中为我)也在接收推送通知.我试图做的是获取当前用户的用户名,然后创建一个用户查询,查询用户名不等于当前用户用户名的所有用户.

What's happening is when I send the message, the sender (in this case me) is receiving the push notification as well. What I tried to do is get the current user's username and then create a user query that queries for all users whose usernames are not equal to the current user's username.

但是,它没有用,消息也被发送给了包括发件人在内的所有用户.

However, it didn't work, the message was also being sent to all users including the sender.

注意:我也试过使用 [query whereKey:@"username" notEqualTo:currentUsername];仅用于调试,当我尝试发送消息时,发件人和任何其他设备都没有收到它.(实际上除了发件人之外没有人应该收到它).

Note: I also tried using [query whereKey:@"username" notEqualTo:currentUsername]; just for debugging, and when I try to send the message, neither the sender nor any other device receives it. (when actually no one should receive it except the sender).

任何帮助将不胜感激.谢谢.

Any help would be greatly appreciated. Thank you.

推荐答案

你的问题是 PFPush 不能接受任何查询,它需要一个 PFInstallation 查询.当您为每个用户存储 PFInstallation 时,您可以添加一个指向当前用户的字段,例如:

Your problem is that a PFPush can't take any query, it needs a PFInstallation query. When you store your PFInstallation for each user, you could add a field that points to the current user, something like:

PFInstallation *currentInstallation = [PFInstallation currentInstallation]; currentInstallation[@"user"] = [PFUser currentUser]; [currentInstallation saveInBackground];

然后,执行如下安装查询:

Then, do an installation query like this:

PFQuery *installationQuery = [PFInstallation query]; PFUser *current = [PFUser currentUser]; [installationQuery whereKey:@"user" notEqualTo:current];

然后,使用此查询继续推送:

Then, continue with your push using this query:

PFPush *push = [[PFPush alloc] init]; [push setQuery:installationQuery]; // <<< Notice query change here [push setMessage:message]; [push sendPushInBackground];

更多推荐

向查询中的所有用户发送推送通知

本文发布于:2023-10-24 17:22:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524547.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:用户发送   通知

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!