iOS/Parse - 向特定用户发送推送通知

iOS/Parse - Sending Push Notifications to Specific User

我正在开发一款允许 "current user" 查看其他用户发布的活动的应用程序。当当前用户加入活动时,我想向发布活动的用户发送推送通知。我已经使用 Parse 为我的应用程序设置了推送通知。我可以通过频道向所有用户发送推送通知,但我仍然不知道如何向特定用户发送推送通知。我可以在 phone.

上收到推送通知

我尝试使用以下代码将设备与用户相关联:

PFInstallation *installation = [PFInstallation currentInstallation];
installation[@"user"] = [PFUser currentUser];
[installation saveInBackground];

不幸的是 - 这让我的应用程序崩溃了。不知道为什么没有错误信息。

我正在考虑使用以下代码向特定用户发送推送通知。 (这是我从 Parse 文档中获得的代码)

// Create our Installation query
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"injuryReports" equalTo:YES];

// Send push notification to query
PFPush *push = [[PFPush alloc] init];
[push setQuery:pushQuery]; // Set our Installation query
[push setMessage:@"Willie Hayes injured by own pop fly."];
[push sendPushInBackground];
  1. 如何将安装与当前用户相关联?
  2. 我走对了吗?
  3. 如果您知道好的教程,请告诉我,或者如果您已经实现了类似的东西并且可以帮助我解决这个问题。

谢谢,

您首先需要在用户与其安装之间建立关系。请记住,iOS 上的通知会发送到设备,因为 Apple 通知系统对您的用户一无所知。

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

现在您的代码更易于使用:

// Create our Installation query
PFQuery *pushQuery = [PFInstallation query];
// only return Installations that belong to a User that
// matches the innerQuery
[query whereKey:@"user" matchesQuery: pushQuery];

// Send push notification to query
PFPush *push = [[PFPush alloc] init];
[push setQuery:pushQuery]; // Set our Installation query
[push setMessage:@"Willie Hayes injured by own pop fly."];
[push sendPushInBackground];