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

iOS/Parse-向特定用户发送推送通知,ios,objective-c,parse-platform,push-notification,Ios,Objective C,Parse Platform,Push Notification,我正在开发一个允许“当前用户”查看其他用户发布的事件的应用程序。当当前用户加入事件时,我希望向发布事件的用户发送推送通知。我已使用Parse为我的应用程序设置推送通知。我可以通过一个通道向所有用户发送推送通知,但我仍然无法确定如何向特定用户发送推送通知。我可以在手机上接收推送通知 我尝试将设备与具有以下代码的用户关联: PFInstallation *installation = [PFInstallation currentInstallation]; installation[@"user"

我正在开发一个允许“当前用户”查看其他用户发布的事件的应用程序。当当前用户加入事件时,我希望向发布事件的用户发送推送通知。我已使用Parse为我的应用程序设置推送通知。我可以通过一个通道向所有用户发送推送通知,但我仍然无法确定如何向特定用户发送推送通知。我可以在手机上接收推送通知

我尝试将设备与具有以下代码的用户关联:

PFInstallation *installation = [PFInstallation currentInstallation];
installation[@"user"] = [PFUser currentUser];
[installation saveInBackground];
不幸的是,这使我的应用程序崩溃。不确定为什么没有错误消息

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

  • 如何将安装与当前用户关联
  • 我走对了吗
  • 如果你知道一个好的教程,请让我知道,或者如果你实现了类似的东西,可以帮助我解决这个问题
    谢谢,

    您首先需要在用户及其安装之间建立关系。请记住,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];
    

    你是对的-你需要在用户和它的安装之间建立关系。然后,获取要发送通知的用户,并检查安装中是否存在该用户。您可以在内部查询[query whereKey:@“user”matchesQuery:someUser];-终于成功了,谢谢!
    // 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];