Parse, how to send push notification to targeted users

前端 未结 1 1482
醉话见心
醉话见心 2021-01-24 01:44

I have successfully setup parse push notifications and in my installation table I have both an installation, and device token. What I\'m really trying to do is send a push notif

相关标签:
1条回答
  • 2021-01-24 02:28

    From https://parse.com/docs/push_guide#top/iOS, section "Using Advanced Targeting".

    You can even create relationships between your Installation objects and other classes saved on Parse. To associate a PFInstallation with a particular user, for example, you can simply store the current user on the PFInstallation.

    // Associate the device with a user
    PFInstallation *installation = [PFInstallation currentInstallation];
    installation[@"user"] = [PFUser currentUser];
    [installation saveInBackground];
    

    Now you can create a query on the installation table, where "user" is the user you want to send a push notification to.

    Finally, use that query when constructing the push object.

    Example in Objective-C (adjust accordingly, if you're sending the push in some other language):

    PFQuery *pushQuery = [PFInstallation query];
    [pushQuery whereKey:@"user" equalTo:someUser]; // where some user is the user object that is to receive a push notification
    
    PFPush *push = [[PFPush alloc] init];
    [push setQuery:pushQuery];
    [push setMessage:@"Hi there!"];
    [push sendPushInBackground];
    
    0 讨论(0)
提交回复
热议问题