gpt4 book ai didi

ios - 如何向用户好友发送推送通知

转载 作者:行者123 更新时间:2023-11-29 02:27:37 24 4
gpt4 key购买 nike

每个安装我的 iOS 应用程序的用户都会创建一个 Parse 用户。在 Parse User 类中,我有一个设备名称,它是指向 Install 类的指针和一个 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代码并部署来解析云。

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。但下面的打印什么也没得到。

  console.info(senderUser.friendFBIDs);

请帮助我解决我做错的事情。

最佳答案

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

按照您的意愿将此人订阅到 channel :

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

您现在会注意到,在您的 Parse.com 核心数据的安装类中,该设备已订阅了您的 friendsFBID channel 。

然后通过您实现的任何操作来发送您发送到 channel 的推送:

// 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];

关于ios - 如何向用户好友发送推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27311284/

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