如何向用户好友发送推送通知 [英] How to deliver a push notification to user friends

查看:47
本文介绍了如何向用户好友发送推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个安装我的 iOS 应用程序的用户我都在创建一个解析用户.在 Parse User 类中,我有一个设备名称,它是一个指向 Install 类的指针和一个 Parse Users 数组.

Every user who installs my iOS App I am creating a Parse User. In the Parse User class I have a device Name which is a pointer to Install class and an array of Parse Users.

  PFUser *newUser = [PFUser user];      
  newUser.username = [NSString stringWithFormat:@"%@ %@",[user first_name],[user last_name]];
  newUser.password = [user objectID];
  [newUser setObject:[PFInstallation currentInstallation] forKey:@"device"];
  newUser[@"friendFBIDs"] = _allMyFBFriends;
  [newUser signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (!error) {
      NSLog(@"Registration success!");
      [defaults setBool:YES forKey:@"PARSE_USER_CREATED"];
      [self performSegueWithIdentifier:@"login" sender:self];
    }
  ];

现在我想向所有这些安装发送通知.我已经创建了一个 node.js 代码并部署到解析云中.

Now I want to send notification to all these installations. I have created a node.js code and deployed to parse cloud.

Parse.Cloud.define("sendPushToUser", function(request, response) {
  var senderUser = request.user;
  var recipientUserId = request.params.recipientId;
  var message = request.params.message;

现在根据recipientUserId,我想查询用户表并获取所有friendFBID.然后遍历它们中的每一个以获取它们各自的设备.检索我拥有的数组的代码是 senderUser.friendFBIDs.但是下面的打印什么也没有.

Now depending on the recipientUserId I want to query the User Table and get all friendFBIDs. Then iterate through each of them to get their respective devices. The code to retrieve the array I have is senderUser.friendFBIDs. But the print below gets nothing.

  console.info(senderUser.friendFBIDs);

请帮助我解决我做错的地方.

Please help me with what I am doing wrong.

推荐答案

我只想指出 PFQueryTableViewController 更适合您的应用程序,并且提供了更简单的访问途径,因为您只查询一个类.它还有更好的功能,比如自动缓存表格查询,但它不是我的应用程序,所以你可以试试这个

I just want to point out that PFQueryTableViewController is a better fit for your app and offers a simpler avenue of access since your only querying one class. It also has better features like automatic caching Query for table but it's not my app so you can try this

通过以下方式让此人订阅频道:

Subscribe the person to a channel however you wish by :

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation addUniqueObject:@"friendsFBID" forKey:@"channels"];
[currentInstallation saveInBackground];

您现在会注意到,在 Parse.com 的核心数据中的安装类中,设备已订阅您的朋友 FBID 频道.

You will now notice that on the Installation class in your Core Data of Parse.com the device has subscribed to your friendsFBID channel.

然后通过您实施的任何操作来发送您以这种方式发送到频道的推送:

Then through whatever action you implement to send a push you send to channels this way:

// Send a notification to all devices subscribed to the "friendsFBID" channel.
PFPush *push = [[PFPush alloc] init];
[push setChannel:@"friendsFBID"];
[push setMessage:@"Your message here"];
[push sendPushInBackground];

这篇关于如何向用户好友发送推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆