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"