Same device can be registered multiple times (iOS)

5 posts, 1 answers
  1. Petri
    Petri avatar
    7 posts
    Member since:
    Jun 2014

    Posted 05 Sep 2014 Link to this post

    We have a PhoneGap 3.5 application using Telerik Backend services to manage Push Notifications.

    Everything works fine until we uninstall the app and then reinstall it (on iPhone). We can still see the device on the Backends device list but the getRegistration() callback is returning not found (err.code === 801). This leads to a big problem, as the device is been registered multiple times and will also receive as many messages as there are registrations.

    The problem does not occur on Android or if I just restart the app on iOS. On Android, if I try to register the device twice, the callback returns an error(err.code === 601), but this is not happening here. I don't think I fully understand how the Backend service identifies that the requesting device is already been registered? I can see that the Hardware ID is different, but how is it generated? Push Token seems to be the same every time.

    Additional information:
    * we are using development certificates for iOS
    * we are using PhoneGap Build to build the app
    * I have tried to change the order of execution of enabling for device(enableNotifications()) and getting registration info(getRegistration()), but it doesn't seem to matter in which order it is done
    * the test device is a iPhone 4S using iOS 7.1.2







  2. Answer
    Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 05 Sep 2014 Link to this post

    Hi Mika,

    Thank you for contacting.

    The JS SDK of Backend Services obtains the device ID (e.g. the HardwareId field in the device registration in BS) by using the Cordova Device plugin. Please, refer to this link of the official GitHub repository for the plugin:
    Cordova Plugin Device Universally Unique Identifier. Unfortunately, there are some quirks occurring in iOS and Windows devices which you can examine in the readme file of the plugin. One of them is exactly the one you just encountered. The currentDevice.getRegistration() method retrieves the HardwareId of the device and calls https://api.everlive.com/v1/ApiKey/Push/Devices/HardwareId/the-hardware-id-here. As the hardware Id is already a new one, the device is not found and needs to be registered.

    One approach you may consider is to generate a unique Id for the app on the device yourself (a GUID for example) and persist it somewhere. You can persist it throughout subsequent app installations by storing it in the iOS Keychain. You can use the KeychainPlugin for this. You have to get the unique Id on each app start and pass it to the API. Then you can change the _getDeviceId() method of the JS SDK to return this Id or register the device through the REST API.

    Please, let me know if you have further questions.


    Best regards,

    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  3. Petri
    Petri avatar
    7 posts
    Member since:
    Jun 2014

    Posted 07 Nov 2014 in reply to Anton Dobrev Link to this post

    Sorry for the late response and thank you Anton for your fast response on my original post.

    I was able to solve the issue thanks to your advice. I create my custom unique HardawareID (if it does not exist already) and store it in the iOS keychain. After that I use the REST API to communicate with the Backend services. Works like a charm.

    Thanks.
  4. Max
    Max avatar
    19 posts
    Member since:
    Jan 2015

    Posted 31 Mar 2015 Link to this post

    just stumbled upon the exact same issue with device being registered multiple times, thanks for this solution.

    however, this seems kinda essential to me, so wouldn't it be possible to include this solution already into the telerik push plugin?
  5. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 02 Apr 2015 Link to this post

    Hi,

    @Max
    Thanks for your input.

    Indeed, this approach could be one of the possible solutions you can use as suggested by the community.

    The Device plugin currently uses the oldest - CFUUIDCreate method to obtain an UUID and saves it to the NSUserDefaults storage (which as far as I remember is suggested by Apple), thus it is persisted between starts of the app but not installations. Another approaches include the Keychain or the Pasteboard, but indeed, each one has some benefits over the others in some cases. Thus each developer has the ability choose the approach that suits best.

    Since the JS SDK of Backend Services is just a wrapper around the Cordova plugins (the device Id is obtained via the Device plugin of Cordova) it seems a cleaner solution to rely on the native behavior as exposed by the plugins.

    In regard the Telerik Push Plugin - it is available to all the community and does not work only within the Telerik Platform. On the other hand, it does not handle the device registration to a backend server - it handles only the native push functionality for each platform. Having said that, it is not a responsibility of the plugin to determine the device Id or handle it.

    Please, let me know if further questions arise.

    Best regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
Back to Top