Sending Push Notification from mobile to particula

2019-05-26 15:12发布

问题:

I have saved user pointer in instalation class. Web backend shows 0 subscribers

I am sending notification using below code

 PFQuery *qry = [PFUser query];
        [qry getObjectWithId:friendObject.objectId]; //friend object is ok like @"Fefl5x7nhl"

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

        // Send push notification to query
        PFPush *push = [[PFPush alloc] init];
        NSString *msgString=[NSString stringWithFormat:@"%@ :%@",
                             [newMessage objectForKey:@"userName"],
                             tfEntry.text];
        [push setQuery:pushQuery]; // Set our Installation query
        NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
                              msgString, @"alert",
                              @"ursound.caf", @"sound",
                              @"Increment", @"badge",
                             // @"Optionally a type was set", @"type",
                              nil];
        [push setData:data];
       [push sendPushInBackground];

My installation class does have this user pointer (friend object) and logically it should be receiver of the notification .

AM i missing something? any suggestion would be great . Thanks for your valuable time

回答1:

As long as you have a column on the Installation class called user that is of type Pointer<My_User> and you've actually populated it, your code should work.

There's a section in the Push Notification documentation that talks about adding data to the Installation class:

https://parse.com/docs/push_guide#sending-queries/iOS