gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 13:45:43 25 4
gpt4 key购买 nike

我正在尝试向单个用户发送推送通知,并且我按照找到的指令 here 进行操作。

这是我的代码:

    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)
}
}

我调试了这段代码,并且能够到达“成功”语句。

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

PUSH ID
JXJmO93vau

TARGETING
currentUser advanced operator ($inQuery {"className"=>"_User", "where"=>{"objectId"=>"QlhXkNWET6"}})
SENDING TIME
January 23rd, 2016 at 8:14 PM

EXPIRATION
None

FULL TARGET
{
"currentUser": {
"$inQuery": {
"className": "_User",
"where": {
"objectId": "QlhXkNWET6"
}
}
}
}

FULL DATA
{
"alert": "Alert !!",
"title": "Some Title"
}

ERROR:
error 102: bad type for $inQuery parse.com/api/collections/collection.go:393
inQueryVisitor.runChildQuery parse.com/api/collections/collection.go:367
inQueryVisitor.Visit <autogenerated>:171 (*inQueryVisitor).Visit
parse.com/api/types/query/visitor.go:27 Visit
parse.com/api/collections/collection.go:407 (*Collection).resolveInQueries
parse.com/api/collections/collection.go:554 (*Collection).PrepareQuery
parse.com/api/collections/installation_collection.go:740
(*InstallationCollection).Iterate parse.com/push/expansion/expansion_job.go:360
(*Job).iterateOverDevices parse.com/push/expansion/expansion_job.go:296
(*Job).perform parse.com/push/expansion/expansion_job.go:184 (*Job).Perform
parse.com/resque/service.go:420 (*Service).perform parse.com/resque/service.go:144
(*Service).Work.func1 /usr/local/go/src/runtime/asm_amd64.s:1722 goexit

任何帮助将不胜感激!

最佳答案

我通过在 PFInstallation 中创建一个“currentuser”列并首先向其中注册当前用户来解决这个问题。我放弃了使用“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()

关于ios - 无法使用 Parse 向单个用户发送推送通知 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34971143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com