In iOS, I need to associate BackendlessUsers with their device that gets saved to the Messages console. This is because I need to send push notifications to individual users.
However, I am unsure how to obtain and save the “Device id” that gets saved to the Messages console: http://support.backendless.com/public/attachments/d81cc215e03182a18a2814388a9f5faa.png</img>
If I am able to save this device id value, I can map it to a class named UserDevice that stores the deviceID and also points to its corresponding user. I know you can also just save the deviceId as a custom property on the BackendlessUser. However, I just don’t know when you can obtain this value.
After reading the docs, I thought you get it the following way:
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let deviceTokenStr = backendless.messagingService.deviceTokenAsString(deviceToken)
backendless.messagingService.registerDeviceToken(deviceTokenStr, response: { (deviceId) -> Void in
//save deviceId here ...
}
However, the deviceID returned to me within the closure is different from the deviceID that is saved to the Messages console.
So what method gives me the correct deviceID that gets saved to the Messages console and be used for sending pushes to that specific device?
There are android examples show a way to assign you own device id. is there no way to do it is iOS(swift). Here is what works in android
Messaging.DEVICE_ID = strDeviceID; // This unique id this device to the backend server using userInfo
Backendless.Messaging.registerDevice(getResources().getString(R.string.gcm_project_num), new AsyncCallback<Void>() {
@Override
public void handleResponse(Void response) {
Log.i("App","Device ID has been registered for Push Notifications");
}
@Override
public void handleFault(BackendlessFault fault) {
Log.e("App","Device IDFALLED to registered for Push Notifications " + fault.getMessage());
}
});