Parse.com - 将推送通知安装对象ID与用户相关联

时间:2014-08-24 12:47:26

标签: push-notification parse-platform

我不确定如何将推送通知安装对象ID与特定用户相关联。是否有某种元数据可以发送以连接某种用户ID?

1 个答案:

答案 0 :(得分:0)

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

这会将用户置于一个列" user"在Installation表中,该列将是指向_User表的指针。

以下是用户如何发送推送定位,假设您的用户表具有" firstName"柱:

// Find users
PFQuery *userQuery = [PFUser query];
[userQuery whereKey:@"firstName" equalTo:"Bob"];

// Find devices associated with these users
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"user" matchesQuery:userQuery];

// Send push notification to query
PFPush *push = [[PFPush alloc] init];
[push setQuery:pushQuery]; // Set our Installation query
[push setMessage:@"Hi Bob, thanks for using my app!"];
[push sendPushInBackground];