3
votes

I'm trying to send push notifications to to a list of my Facebook friends. I have stored Facebook IDs with every Parse User and also saved that user in Parse Installation. There's a problem with the Android implementation as notifications are not sent to all friends when they are sent from an Android device but all friends receive the notification when it is sent from an iOS device. Below is my code for sending notifications from both iOS and Android.

The Targeting field for push from Android is as follows :

user advanced operator ($inQuery {"where"=>{"fbid"=>{"$in"=>[“id1”, “id2”, “id3”, “id4”]}}, "className"=>"_User"}) deviceType is any of "ios", "android", "winphone", or "js"

While the Targeting field for push from iOS is as follows :

user advanced operator ($inQuery {"className"=>"_User", "where"=>{"fbid"=>{"$in"=>["id1", "id2", "id3", "id4"]}}}) deviceType is any of "ios", "android", "winphone", or "js"

Yet the notification is only sent to 1 user instead of 4 in case of Android (based on the 'Subscribers' field in Push Notification). While in case of iOS, all friend's whose IDs are in the list receive notification.

Any help would be appreciated.

Code for iOS :

NSMutableArray *friendsArray;
PFQuery *friendQuery = [PFUser query];
[friendQuery whereKey:[NSString stringWithUTF8String:@"fbID"] containedIn:friendsArray];

PFQuery *query = [PFInstallation query];
[query whereKey:@"user" matchesQuery:friendQuery];

PFPush *push = [[PFPush alloc] init];
[push setQuery:query];

[push setMessage:[NSString stringWithFormat:@"%@ sent you this test message!", [NSString stringWithCString:"TestUser" encoding:NSUTF8StringEncoding]]];
[push sendPushInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (!error) {
        NSLog(@"Push sent to users successfully");
    }
    else {
        NSLog(@"Error while fetching sending push from Parse: %@ %@", error, [error userInfo]);
    }
}];

Code for Android :

List<String> friends;
ParseQuery<ParseUser> friendQuery = ParseUser.getQuery();
friendQuery.whereContainedIn("fbID", friends);

ParseQuery<ParseInstallation> query = ParseInstallation.getQuery();
query.whereMatchesQuery("user", friendQuery);

ParsePush push = new ParsePush();
push.setQuery(query);
push.setMessage(userFullName + " sent you this test message from Android!");
push.sendInBackground();

EDIT :

I found the issue. I get this exception as a result of the ParseInstallation query.

com.parse.ParseException: Clients aren't allowed to perform the find operation on the installation collection.

How do I fix this?

1

1 Answers

0
votes

Apps using the ClientKey aren't allowed to query the Installation class.

I would suggest to use unique channels, using a channel you can target your push messages for specific users.