无法使用Parse - Swift向单个用户发送推送通知

时间:2016-01-24 01:21:55

标签: ios swift mobile parse-platform

我正在尝试向单个用户发送推送通知,并且我按照发现的here

指令进行操作

这是我的代码:

tweets
      /$tweetId
           /userId
           /date

followers
      /$userId
            /$followerId

我调试了这段代码,并且我能够达到成功"言。

但是在解析网站上,我收到以下错误:

    let message = "Alert !!"
    let id = "QlhXkNWET6"

    let data = [ "title": "Some Title",
        "alert": message]

    let userQuery: PFQuery = PFUser.query()!
    userQuery.whereKey("objectId", equalTo: id)
    let query: PFQuery = PFInstallation.query()!
    query.whereKey("currentuser", matchesQuery: userQuery)

    let push: PFPush = PFPush()
    push.setQuery(query)
    push.setData(data)
    push.sendPushInBackgroundWithBlock { (success:Bool, error:NSError?) -> Void in
        if success{
            print("success")
        }
        else{
            print(error)
        }
    }

任何帮助都将非常感谢!

1 个答案:

答案 0 :(得分:0)

我能够通过创建一个" currentuser"来解决这个问题。 PFInstallation中的列,首先注册当前用户。我放弃使用" ObjectId"因为使用电子邮件更有意义。

这是在用户第一次注册时完成的。

let currentInstallation = PFInstallation.currentInstallation()
currentInstallation.addUniqueObject("currentuser", forKey: "channels")
currentInstallation["currentuser"] = self.emailTF.text! // adding this user email
currentInstallation.saveInBackground()

现在已完成此用户的注册,您可以通过执行以下操作将此添加到按钮或其他任何位置来向此用户发送推送通知:

    let pushQuery = PFInstallation.query()
    pushQuery!.whereKey("user", equalTo: "some@email.com")

    // Send push notification to query
    let push = PFPush()
    push.setQuery(pushQuery) // Set our Installation query
    push.setMessage("New Message In coming")
    push.sendPushInBackground()