我正在尝试向所选用户发送通知。单击“发送”按钮后,程序会将通知发送给选定的用户。这是我第一次收到通知,而且我不知道我是否正确这样做。如果有人可以帮助我那将是伟大的! :) 以下是我对此的尝试。
var setOfSelectedFriends = Set<String>()
func send(sender: UIButton){
pushNotifications()
}
func pushNotifications(){
let message = "Alert!"
let data = ["title": "Some Title", "alert": message]
var userQuery: PFQuery = PFUser.query()!
userQuery.whereKey("username", equalTo: setOfSelectedFriends)
let query: PFQuery = PFInstallation.query()!
query.whereKey("username", matchesQuery: userQuery)
var push: PFPush = PFPush()
push.setQuery(query)
push.setData(data)
push.sendPushInBackground()
}
这是我的appdelegate
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let installation = PFInstallation.currentInstallation()
installation.setDeviceTokenFromData(deviceToken)
installation.saveInBackground()
}