How come the Device ID that I can see in the Backendless console in Messaging different from what I can see as the deviceId I see in “didRegisterForRemoteNotificationsWithDeviceId” in the debug log?
Hi Jorgen,
Could you please provide both so we can compare?
Hi Sergey,
I’ve attached a screenshot of the listed device in the Messaging screen on the cosole.
The debug log shows:
didRegisterForRemoteNotificationsWithDeviceId: 7128F851-A499-FD77-FF28-A96074315900"
However, if it is possible to send, using Swift, a push notification and other messages by using the deviceToken to a specific device, or devices, this would work just as well.
What do you mean by “debug log”? Is it some log you manually output or a Backendless Log?
Also I haven’t really understood what you meant in this sentence:
However, if it is possible to send, using Swift, a push notification and other messages by using the deviceToken to a specific device, or devices, this would work just as well.
Yes you can send by deviceToken, or what’s the question?
The debug log is from Xcode. You have a function
func didRegisterForRemoteNotificationsWithDeviceId(deviceId: String!, fault: Fault!) {} and the deviceId there is different from what is registered in the console.
The question I had about the push notification was to see if it was possible to target a specific device by it’s deviceToken when building and app with Swift.
Please provide a sample of the code which will reproduce the problem, so that we see that the problem is definitely with our service.
As to your second question, you can only target the devices by deviceId, not by deviceToken. See the docs on it here: https://backendless.com/documentation/messaging/ios/messaging_publish_push_notifications.htm
In the AppDelegate;
// MARK: - Push Notification Handlers
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
backendless.messaging.didRegisterForRemoteNotificationsWithDeviceToken(deviceToken)
debugPrint("did register for remote notification")
debugPrint("deviceToken: \(deviceToken)")
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
backendless.messaging.didFailToRegisterForRemoteNotificationsWithError(error)
debugPrint("did fail to register for remote notification: \(error)")
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
backendless.messaging.didReceiveRemoteNotification(userInfo)
debugPrint("did recieve remote notification: \(userInfo)")
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
backendless.messaging.didReceiveRemoteNotification(userInfo)
completionHandler(.NewData)
debugPrint("did recieve remote notification: \(userInfo)")
}
In the MainViewController; which calls on IBEPushReceiver
// MARK:- IBEPushReceiver Methods
func didReceiveRemoteNotification(notification: String!, headers: [NSObject : AnyObject]!) {
debugPrint("RECEIVED: \(headers["publisher_name"]) -> \(notification)")
let systemSoundID: SystemSoundID = 1020
AudioServicesPlaySystemSound (systemSoundID)
let alertViewController = UIAlertController(title: "Message", message: notification, preferredStyle: .Alert)
let okAction = UIAlertAction(title: "OK", style: .Default) { (action) -> Void in
// action code
}
alertViewController.addAction(okAction)
presentViewController(alertViewController, animated: true, completion: nil)
}
func didRegisterForRemoteNotificationsWithDeviceId(deviceId: String!, fault: Fault!) {
if fault == nil {
debugPrint("didRegisterForRemoteNotificationsWithDeviceId: \(deviceId)")
}
else {
print("didRegisterForRemoteNotificationsWithDeviceId: \(fault)")
}
}
Hi Jorgen,
didRegisterForRemoteNotificationsWithDeviceId: delegate returned device registration id, not deviceId.
I understand. Has it been fixed, or is that the intended return?
That’s how it has been all along.