gpt4 book ai didi

ios - 快速发送和接收推送通知

转载 作者:可可西里 更新时间:2023-11-01 02:20:10 24 4
gpt4 key购买 nike

enter image description here我在 swift 中使用 Parse 作为我的数据库创建了一个小型 Messenger 应用程序。我希望每次任何用户发送消息时,只有 10 米内的其他用户才能收到通知。该应用程序正在运行,但推送通知不起作用。我做了一些研究,看起来我的代码与我发现的代码相似但仍然无法正常工作。请帮我。谢谢

   var CurrentLocation : PFGeoPoint = PFGeoPoint(latitude: 44.6854, longitude: -73.873) // assume the current user is here
let userQuery = PFUser.query()
userQuery?.whereKey("Location", nearGeoPoint: CurrentLocation, withinMiles: 10.0)
let pushQuery = PFInstallation.query()
pushQuery?.whereKey("username", matchesQuery: userQuery!)
let push = PFPush()
push.setQuery(pushQuery)
push.setMessage(" New message")
push.sendPushInBackground()

最佳答案

您的问题是行 pushQuery?.whereKey("username", matchesQuery: userQuery!)。根据解析文档 警告:这仅适用于键的值为 PFObjects 或 PFObjects 数组的情况。在此处阅读更多信息:https://parse.com/docs/osx/api/Classes/PFQuery.html#//api/name/whereKey:matchesQuery而是通过首先执行第一个查询然后将 userId 的字符串用于在第一个 completionBlock 内执行的第二个查询来更改它以链接查询。

更新

此外,作为旁注,您不遵守 swift 的驼峰式大小写规则以及 Parse 制定的规则。你应该遵循惯例。 (有关 Parse 和变量名称中键的正确大小写,请参阅我的代码)。

例子:

var currentLocation : PFGeoPoint = PFGeoPoint(latitude: 44.6854, longitude: -73.873) // assume the current user is here
let userQuery = PFUser.query()
userQuery?.whereKey("location", nearGeoPoint: currentLocation, withinMiles: 10.0) // Note I changed Location to location
userQuery?.findObjectsInBackground({ results, error in
let usernames = (results as! [PFObject]).map { $0.username }
let pushQuery = PFInstallation.query()
pushQuery?.whereKey("username", containedIn: usernames)
let push = PFPush()
push.setQuery(pushQuery)
push.setMessage("New message")
push.sendPushInBackground()
})

另请注意,您可能需要更改您的结构,因为 PFInstallation.query 的文档指出您必须使用三个查询参数之一,而您没有使用(您可能必须将安装对象 ID 保存到用户。然后,不要使用用户名创建一个数组,而是使用安装对象 ID 创建一个数组,然后像这样查询 PFInstallation。但是,这可能仍然有效,所以先尝试一下,你永远不知道。

关于ios - 快速发送和接收推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31210063/

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