Sending User-to-User Push Notification Problems with Parse and Swift

I am having trouble sending push notifications from user to user. I am using Parse backend and all my code is in Swift. I can add a push notification to the server without issue, but I cannot add a push listener without getting an error that highlights [PFInternalUtils assertValidClassForQuery:]. I know it has something to do with how I am requesting the addressee, but I don’t know how to fix it. Any help is appreciated. Here is my complete code:

    let message: NSString = responseMessage.text as NSString

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

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

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

      

Works If I select request, the code works with just sending a push message in Parse:

    let message: NSString = responseMessage.text as NSString

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

    var push: PFPush = PFPush()
    push.setData(data)
    push.sendPushInBackground()

      

This is a suspicious code

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

    push.setQuery(query)

      

Also for reference

recipientObjectId is the objectId of the user who should receive the push notification. It is saved as an NSString.

The "currentUser" key in my installation class is a pointer to the user who owns this installation.

EDIT

Forgot to give console output. The console output reads: "NSInvalidArgumentException", reason: "Unable to execute comparison query for type: PFQuery"

+3


source to share


1 answer


Found the answer!

Instead of using

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

      



Correct code

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

      

+3


source







All Articles