0

I am trying to send a push notification to a particular recipient. I am just practising for now with a hard coded array of object ids which exist on my parse back end.

I am calling the code in the appDelegate. I have the correct entitlements in my certificates and profiles. In the parse dashboard, it says the notifications are sending but they are not being received on the test devices. The test devices can receive notifications that are sent from the parse dashboard. I have included the required frameworks.

Code: func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { let installation = PFInstallation.currentInstallation() println("did register with device token (deviceToken)") installation.setDeviceTokenFromData(deviceToken) installation.saveInBackground() println("the object id may be (installation.objectId)")

 let query = PFQuery() let objectIDArray : [String] = ["uQfdVtB6pk","kUL0EeXjzY", "6uGdmKv599"] for object in objectIDArray { println("objectid is \(object)") let message: NSString = "test" as NSString var data = [ "title": "Some Title", "alert": message] var userQuery: PFQuery = PFUser.query()! userQuery.whereKey("objectId", equalTo: object) var query: PFQuery = PFInstallation.query()! query.whereKey("Installation", equalTo: installation) query.whereKey("device_id", equalTo: object) var push: PFPush = PFPush() push.setQuery(query) push.setData(data) push.sendPushInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in if success { println("IN success") } else { println("IN ERROR WITH \(error?.localizedDescription))") } } } } 

I am getting into the "IN SUCCESS"

1 Answer 1

0

Where are you running this code from? Also, what is "device_id"? Is that another column you added to the Installation class?

You probably will want to add a pointer to the current user inside of the Installation class. That way you can query for the installations of particular users in the future.

You also don't need to use a for loop to go through all of the objectIds. All of this can be handled using one query using the following:

var query: PFQuery = PFInstallation.query()! query.whereKey("objectId", containedIn: objectIDArray) var push: PFPush = PFPush() push.setQuery(query) push.setData(data) push.sendPushInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in if success { println("IN success") } else { println("IN ERROR WITH \(error?.localizedDescription))") } } 
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the tip on the objectIDArray. I got it working in the end. I got 20 notifications last night at random times so I think there was just a severy lag for a while
this did not work for me. It sends to the first item in the array and no others...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.