I successfully received the push notification, but when I swipe down from the top of the screen, the notification isn’t being shown. However, I am in fact able to change the badge number. Is there something else that I am missing?
Hi Michael,
You should set backendless.messaging.notificationTypes somewhere, in viewDidLoad(), for example:
backendless.messaging.notificationTypes = UIUserNotificationType.Alert.rawValue | UIUserNotificationType.Sound.rawValue | UIUserNotificationType.Badge.rawValue
Regards,
Slava
My fault, I was testing it while the app was open. Set a delay after testing an asynchronous publish and got it. Thanks
Ok so it worked at some point yesterday but don’t know what’s going on.
- I have set up my certificate, provisioning profile, and app id (with push notifications enabled. My AppDelegate looks like:
//didFinishLaunching
//initializes backendless which is being used for storing user data
backendless.initApp(APP_ID, secret:SECRET_KEY, version:VERSION_NUM)
backendless.userService.setStayLoggedIn(true)
//PUSH NOTIFICATIONS
backendless.messaging.registerForRemoteNotifications()
backendless.messaging.notificationTypes = UIUserNotificationType.Alert.rawValue | UIUserNotificationType.Sound.rawValue | UIUserNotificationType.Badge.rawValue
//RELEVANT METHODS
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
// register device with Backendless here
backendless.messaging.registerDeviceToken(deviceToken)
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
backendless.messaging.didFailToRegisterForRemoteNotificationsWithError(error)
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
backendless.messaging.didReceiveRemoteNotification(userInfo)
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
backendless.messaging.didReceiveRemoteNotification(userInfo)
completionHandler(.NewData)
}
- I have set the provisioning profile under targets in xcode
- My device is successfully registered and showing in the console under Messaging -> Devices
- Doing:
let publishOptions = PublishOptions()
publishOptions.assignHeaders(["ios-badge":"1", "ios-sound":"default", "android-ticket-text":"Push notification from Beer Tour!","android-content-title":"\(self.nameField.text!) - \(month) \(dayNum) at \(time)", "android-content-text":"\(self.descriptionField.text)"])
let deliveryOptions = DeliveryOptions()
deliveryOptions.pushPolicy(PUSH_ONLY)
deliveryOptions.pushBroadcast(FOR_ANDROID.rawValue|FOR_IOS.rawValue)
deliveryOptions.publishAt = NSDate(timeIntervalSinceNow: 5)
backendless.messaging.publish(
"default",
message: "\(self.nameField.text!) - \(month) \(dayNum) at \(time)\n\(self.descriptionField.text)",
publishOptions: publishOptions,
deliveryOptions: deliveryOptions,
response: {(status: MessageStatus!) -> () in
print("Message has been sent: \(status)")
},
error: { (fault : Fault!) -> () in
print("Server reported an error: \(fault)")
})
}
Allows me to successfully send a push notification as per the message:
Message has been sent: <MessageStatus> messageId: 8F33FE18-FF8E-44EE-FF47-91D1DD88FE00, status: SCHEDULED errorMessage: (null)
In the backendless console, the .p12 is in fact set, and with the proper password. Additionally, push notifications is set to “on” in capabilities, and background modes is set to “on”, with push notifications being check marked.
Michael, please clarify: does your app work? You wrote in another thread, that my template works for you with your certificates, bundleId, etc. Is this right?
My app does in fact work, meaning it runs and can successful register the device and send a push notification.
Not sure what I am missing that is leading to me not receiving push notifications. I am not receiving any push notifications when they are sent from my android device, nor when I send one via the backendless console.
Update - went through the set up process again using the TestPushNotify example and got:
didRegisterForRemoteNotificationsWithDeviceId: EDFB4539-E8BC-F5AE-FF97-2D977E249D00
PUBLISHED
Message has been sent: <MessageStatus> messageId: 154D3EDC-704F-9A7D-FF42-1298CCC35B00, status: SCHEDULED errorMessage: (null)
However, still no push notification! It didn’t show up in the notification panel, and additionally the didReceiveRemoteNotification didn’t get called either. My device is showing under devices in the console, and it’s not picking up broadcasts or push notifications sent from the console either.
Michael,
If this is going to be of any help, here’s a recording of a webinar I did specifically on the subject of push notifications. Perhaps you could see something that is missing in the process you followed?
Also, did you deploy in Backendless Console a testing or a universal (prod/sandbox) certificate?
Regards,
Mark
Mark,
It ended up being a problem with the certification, thanks for leading be in the right direction. Not sure what I did originally but now it’s working. I restarted xcode and my computer so that might’ve done something as well, lol!
Now that I have push notifications working on android and ios, how do i make it so sending one push notification from one devices sends it to devices on both platforms? Right now, when making a push notification on iOS, all of the iOS devices will pick it up, but none of the android ones will, despite telling it to push to android as per the code below:
let publishOptions = PublishOptions()
publishOptions.assignHeaders(["ios-badge":"1", "ios-sound":"default", "android-ticket-text":"Push notification from Beer Tour!","android-content-title":"\(self.nameField.text!) - \(month) \(dayNum) at \(time)", "android-content-text":"\(self.descriptionField.text)"])
let deliveryOptions = DeliveryOptions()
deliveryOptions.pushPolicy(PUSH_ONLY)
deliveryOptions.pushBroadcast(FOR_ANDROID.rawValue|FOR_IOS.rawValue)
deliveryOptions.publishAt = NSDate(timeIntervalSinceNow: 5)
backendless.messaging.publish(
"default",
message: "\(self.nameField.text!) - \(month) \(dayNum) at \(time)\n\(self.descriptionField.text)",
publishOptions: publishOptions,
deliveryOptions: deliveryOptions,
response: {(status: MessageStatus!) -> () in
print("Message has been sent: \(status)")
},
error: { (fault : Fault!) -> () in
print("Server reported an error: \(fault)")
})
}
What if you try sending it from console with all the same headers? Make sure to copy the all the headers before you click “Send”, the value of the text box disappears and it might be annoying to re-enter it again.
It works perfectly! So what does this mean?
To make it absolutely the same between the code and console, try removing the “publishAt” option and see if it is delivered everywhere.
Sorry for the late reply - unfortunately that didn’t send to the android device.
On a positive note - when I go to the data browser, the # of messages sent incremented by the proper amount. Additionally, sending it via the android device sent it to other android devices AND my iOS device. So the last thing I need to do is having the push sent from ios still reach android
Could you please capture (perhaps using the debugger) the entire value passed into publishHeaders.assignHeaders and post it here?
<PublishOptions> publisherId: (null), headers: {
"android-content-text" = "Come down to have fun!";
"android-content-title" = "Fun Event! - May 21 at 3:18 PM";
"android-ticket-text" = "Push notification from Beer Tour!";
"ios-badge" = 1;
"ios-sound" = default;
}, subtopic = (null)
Ticket text should be “ticker”
Well sir that was it! Please close this as solved.
Thank you and Slav for working with me on this, this support has been phenomenal. When I posted my first question, I had no idea you guys were going to be as active as you are.
Glad you got it resolved!