简体   繁体   中英

Swift Parse : How to Push Notification To a Specific Device/objectId

i'm trying to push notification to a specific user in my User Table, but my function didn't work and i don't understand why.

func testPush(){
    let message = "Alert !!"
    let id = "88yhi9j0"

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

    var userQuery: PFQuery = PFUser.query()
    userQuery.whereKey("objectId", equalTo: id)
    var query: PFQuery = PFInstallation.query()
    query.whereKey("currentUser", equalTo: userQuery)

    var push: PFPush = PFPush()
    push.setQuery(query)
    push.setData(data)
    push.sendPushInBackground()
}

Does anyone have an idea?

The issue is in the line:

query.whereKey("currentUser", equalTo: userQuery)

It should be:

query.whereKey("currentUser", matchesQuery: userQuery)

I hope this solves the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM