问题
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];
}
];
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;
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.
回答1:
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];
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];
来源:https://stackoverflow.com/questions/27311284/how-to-deliver-a-push-notification-to-user-friends