3

I'm having trouble sending push notifications from user to user. I'm using a Parse backend, and all of my code is in Swift. I can add a push notification to the server without issue, but I can't seem to add a push notification receiver without getting an error that highlights [PFInternalUtils assertValidClassForQuery:]. I know it has something to do with how I'm querying for the recipient, 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()

This Works If I take out the query, the code works with just sending a push notification to 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 the suspect 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 that is supposed to receive the push notification. It is saved as an NSString.

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

EDIT

Forgot to give the console output. The console output reads: 'NSInvalidArgumentException', reason: 'Cannot do a comparison query for type: PFQuery'

7
  • Dear user3353890; Can you provide the console output where you get the error [PFInternalUtils assertValidClassForQuery:]? Regards. Commented Oct 11, 2014 at 6:32
  • Of course! My mistake. I had an exception breakpoint on and forget to turn it off to get the console output...the output error states: 'NSInvalidArgumentException', reason: 'Cannot do a comparison query for type: PFQuery' ...I will also amend my question with that. Commented Oct 11, 2014 at 6:41
  • Dear user3353890; can you check the your user query if it return result? I think there is a problem related with return User object(relation). Commented Oct 11, 2014 at 7:08
  • Yes, the userQuery returns an object of the User class. It returns the entire dictionary for the user that I'm searching for. objectId, username, email, etc.... Commented Oct 11, 2014 at 7:18
  • Dear user3353890, As far as I know, if you have a column which is type of Pointer<_User> on Installation table your Push query have to work. Please check again the Push Notification document of Parse which is below link; parse.com/docs/push_guide#sending-queries/iOS Hope this helps, Regards.if you Commented Oct 11, 2014 at 8:02

1 Answer 1

3

Found the Answer!

Instead of using

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

The Correct Code Is

query.whereKey("currentUser", matchesQuery: userQuery)
Sign up to request clarification or add additional context in comments.

1 Comment

Would you mind posting the complete code? Bit confused from all the different ways you tried in your question and then which code you ended up using in its entirety. @user3353890

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.