Multiple push notifications being received

Under Audience/Device Tokens I have my device token duplicated there multiple times... resulting in multiple push notifications being received.

I believe this was due to the placement of 

In func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool

Per the documentation I had:

Then directly after (again per the documentation):
UAirship.push().userPushNotificationsEnabled = true
UAirship.push().defaultPresentationOptions = [.alert, .badge, .sound]

This resulted in:
1) The app crashing and
2) These duplicate entries

What I would like to know is:
1) How can I remove the duplicates and 
2) Will and errant UAirship.push().userPushNotificationsEnabled = true always create a duplicate entry (same token). That seems like a bug to allow this.

Didn't find what you were looking for?

New post



  • Hey Nick,

    Looks like your app is generating new channel ID for the same device token (device token is unique for per device and is generated by the iOS device itself, not Urban Airship).

    This can be caused by various things, like restoring your app to the same device from an iCloud backup. When this happens, your Device Token is not changed but a new Channel ID is generated for the same device and app without uninstalling/unregistering the old ones.

    It's possible something else in your app setup is causing this but calling `UAirship.takeOff()` and

    UAirship.push().userPushNotificationsEnabled = true
    UAirship.push().defaultPresentationOptions = [.alert, .badge, .sound]

    in `didFinishLaunchingWithOptions` should not be the cause as this is the appropriate setup. (It is recomended to call the 2nd two lines later to not annoy users on first launch but for testing purposes it is ok). 

    These lines just trigger iOS's own Enable Push Notification calls, and if you have already opted in, it will not register a new channel or duplicate your token. Nor is it likely to be the cause of a crash. 

    But I can conceive of the crashes and relaunching could cause duplicates perhaps. 

    The first thing we'd need to do is figure out the cause of the crash. Do you have error output from Xcode console you can share? Can you also share the entirety of your code in your app delegate file? 


    Jay M.
    Urban Airship Technical Support

  • Here are a few notes that are relevant:

    1. The crash could not be reproduced when building locally, and only existed (for multiple people) when installed via TestFlight
    2. We will not request this upon app launch for sure, and this was for integration tests only
    3. Removing these lines that were inserted directly after UAirship.takeOff()
    UAirship.push().userPushNotificationsEnabled = true
    UAirship.push().defaultPresentationOptions = [.alert, .badge, .sound]

    The way I can get the log is put the lines back in `didFinishLaunchingWithOptions` , deploy to my test group, and read the log from the device after reproducing.

    Do you recommend this approach?

    Is there a way I can clean up the dupes (clearing Channel IDs or otherwise)

    1. I see. It further suggests those lines are not the issue. 
    2. Great. Thought to mention just in case.
    3. Are you saying that when you had these lines in, some TestFlight users had a crash but then you took it out an no crashes? If this is the only way you can get crash logs, go for it, but it doesn't sound quite right. Trying to think what local vs TestFlight could be different. Either way, without logs or your app code, I can't be sure what is happening. 
    4. As for token clean up, I'm looking into it. Stay tuned. 

    Jay M.
    Urban Airship Technical Support

  • 3. Yes that is exactly it. When the lines were in, it crashed only when installed from TestFlight. Building locally would not produce the crash. Also it would crash with all TestFlight users. 

    Also the timestamps on the token creation indicate to me that is when the duplication happened.

    I'll see if I can reproduce and pull the crash report. If I can't reproduce at this point, then we should be in good shape aside from the cleanup.


  • Hi Jay M.,

    When I go to Audience -> Device Tokens, what I see is 20+ of a single token. 

    The issues I see here are:

    1. None of my TestFlight users are showing up here. This could be because TestFlight uses the AppStore provisioning profile and I had not set up a "Production project" and configured the app for this yet. Please confirm this is a plausible scenario.

    2.  I have 20+ of the same token (mine) .. here ( ... so when I test a notification I get 20+ of them. Why would it retain duplicate tokens?




Please sign in to leave a comment.