0

I'm having a devil of a time trying to do what seems like the simplest possible thing: I want to send a push notification to a particular user, and I already have the PFUser object for that user.

I tried the following:

// 'recipient' is the PFUser
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"owner" equalTo:recipient];

I also tried replacing "owner" with "user". In both cases, the push seems to succeed (no error reported) but the device never gets the notification.

I know that the device is properly registered and logged in because I can send pushe notifications from the Parse web console.

What's the right way to do this?

Thanks, Frank

rici
  • 234,347
  • 28
  • 237
  • 341
user332000
  • 187
  • 1
  • 1
  • 9

2 Answers2

0

I ended up using a nested query to get this.

var userQuery = new Parse.Query(Parse.User);
userQuery.equalTo('objectId', recipient);

var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.matchesQuery('user', userQuery);
picciano
  • 22,341
  • 9
  • 69
  • 82
  • PFQuery* userQuery = [PFUser query]; [userQuery whereKey:@"objectId" equalTo:recipient.objectId]; PFQuery *pushQuery = [PFInstallation query]; [pushQuery whereKey:@"user" matchesQuery:userQuery]; – user332000 Oct 28 '14 at 19:40
  • Oh, silly me. Yes, that was JavaScript that I used in a Cloud Code function. Have you considered writing this as a Cloud Code function instead? – picciano Oct 28 '14 at 19:42
  • Do you have to store a column like `user[Installation] = PFInstallation.current` for the `_User` document? Can you help me check out whether this is set up correctly? http://stackoverflow.com/questions/44089809/parse-cloud-pushquery-matchesquery-never-sends-push-notification-to-receiver – Kesong Xie May 20 '17 at 19:14
0

Ok, it turns out that this is a two-step process.

When the user logs in or creates an account, you have to put a "user" property in PFInstallation:

    [[PFInstallation currentInstallation] setObject:[PFUser currentUser] forKey:@"user"];
    [[PFInstallation currentInstallation] saveEventually];

Only then will the query work.

That seems like a lot of manual work for something that the Parse server should know without my having to set it up.

user332000
  • 187
  • 1
  • 1
  • 9