安装iOS应用程序的每个用户我都在创建一个Parse用户。在Parse User类中,我有一个设备Name,它是指向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);
请帮我解决我的错误。
答案 0 :(得分:1)
我只想指出PFQueryTableViewController更适合您的应用,并提供更简单的访问途径,因为您只查询一个类。它还有更好的功能,如自动缓存查询表,但它不是我的应用程序,所以你可以试试这个
按照您希望的方式将此人订阅到频道:
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation addUniqueObject:@"friendsFBID" forKey:@"channels"];
[currentInstallation saveInBackground];
您现在将注意到,在Parse.com的Core Data中的Installation类中,设备已订阅了您的friendsFBID频道。
然后,通过您实施的任何操作发送推送,您都会以这种方式发送到频道:
// 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];