iOS - Exception: Failed to register the device for remote notifications.

Hello!

I have been trying to add push notifications to iOS for a few days now without much success. At one point I got it to work, got a token but couldn’t send a test notification to the device and now I cannot get the token at all due to the exception in the title. I have searched around without any success and am rather limited in what I can try on my own due to my lack of familiarity with iOS development.

I created an empty project and have been using an old app in the Apple Developer Console in an attempt to isolate and freely play around with it without luck.

Android has been working for a while now, so it’s just iOS that I have had issues with.

Hello! Sorry to hear you’ve been running into issues. You mind answering a few questions to help us troubleshoot further. If you find any of this information sensitive and would rather send it as a DM or by opening a support ticket that works as well.

  • What project is seeing this issue?

  • organization id

  • project id

  • environment id

  • campaign id (or link to the campaign)

  • What Unity version is being used?

  • What package version is being used?

  • What other package versions have been deployed / may be out in the wild? (if applicable)

  • Are you using google / apple / both?

  • What version of iOS / Android are you seeing this problem with?

  • What project is seeing this issue?

  • organization id: 5772896456205

  • project id: 70d72645-0cca-4f7b-ac31-52b8524be2d9

  • environment id: 4eb2d440-6624-4be4-b603-84ab3d4d123e

  • campaign id (or link to the campaign): I am not aware of a campaign

  • Unity version: 2021.3.10

  • Package version: 4.0.0-pre.1

  • Are you using google / apple / both: Both as far as I am aware

  • iOS version: 16.6.1

Hey @ErdionerAPDEV ,
Sorry for a bit late response!
We managed to reproduce the set-up for the push notification for the iPhone 15 Simulator, and were able to see the notification as well as the corresponding events in the dashboard (Analytics → Event Browser).

For our test app, we followed the steps outlined here:

https://docs.unity.com/ugs/en-us/manual/push-notifications/manual/get-started
https://docs.unity.com/ugs/manual/push-notifications/manual/use-push-notifications

as well as the implementation
https://docs.unity.com/ugs/en-us/manual/push-notifications/manual/sdk

Please let us know if your setup maybe diverged in some way, and it would be helpful if you could provide us with the userId and/or deviceId, so we could look your events up, and see if they are valid and if they are reaching the database.
One of the nuances regarding the process when you have a new device, is that it takes some time (cca 3-4 hrs) for new device to propagate to database, therefore you might not see the events in the event browser immediately.

If you know your deviceId, one of the quick ways to test the push is to go to LiveOps → Push Notifications → Settings on your dashboard and make a quick “Send Test”, which bypasses the database and sends the notification to the corresponding device.


Please let us know if this helps

I have had a working version with push notifications version 3.0.1-pre.1 before updating to version 4.0.0-pre.1 and after more than a month realizing that the notifications don’t work anymore (I didnt’ pay attention to the notifications if they stopped coming in earlier or later during this period). There are no analytics events related to registering push notifications, but also no exceptions reported in the “Cloud Diagnostics” section, so I am a bit baffled as to what is going on…

My app is built inside XCode for public release & testflight internal testing, meaning I have to configure my keys and settings with “Sandbox” set to false (this worked previously as well).

However, all the time when trying to register, it throws the error Failed to register the device for remote notifications. It doesn’t tell me anything what went wrong, just that it didn’t work…

More information:

  • Organization ID: 9071037172941
  • Project ID: 4bdb1e48-300d-453c-b90c-10af0d7dcb60
  • Environment ID: a4e7a45e-0a00-4226-ab25-baa370e18e5e
  • User ID: 87a42ff0f07ff4e6db8fce46dc08c9ee
  • Device ID (according to apple): 00008130-0002755E2861401C
  • Unity: 2022.3.10f1
  • Push Notifications: 4.0.0-pre.1
  • Mobile Notifications (dependency): 2.3.0 (manually updated, didn’t work with 2.2.2 as well)

Update: Reverted to previous version of push notifications (3.0.1-pre.1) and registering works again. Something is messed up in the registering flow with the new version.

Hi @MiTschMR

I have tested and managed to reproduce your issue on Unity : 2022.3.12f1.

Push Notifications: 4.0.0-pre.1 - Failed to register the device for remote notifications
reverting to:
Push Notifications: 3.0.1-pre.1 - Notification Token Received : XXXXXXXXX

We’ll investigate further and post guidance here when we have more info

with 2021.3.31f1 I get the same error, with andorid is ok but iOS can not get the token, So frustrating :frowning:

Thanks for your patience whilst we figured out what the problem was. I am pleased to be able to share a solution with you now.

The latest version of the Push Notifications package (4.0.0-pre.1) has a dependency on the Mobile Notifications package. This dependency didn’t exist on the previous version (3.0.1-pre.1).

There are some additional configuration steps that we neglected to add to the PushNotifications > Get Started documentation.

When you install the Push Notifications package (4.0.0-pre.1) it will have automatically pulled in the Mobile Notifications package (v2.3.0). You should be able to check this from the ‘Packages in Project’ section of the Package Manager.

To resolve the device registration error, you will need to navigate to the Editor > Project Settings > Mobile Notifications > iOS settings page and enable notifications and device registration

Now when you call the RegisterForPushNotificationsAsync method, you should receive a device token.

Here’s my minimal test code in case it helps,

   async void Start()
    {
        await UnityServices.InitializeAsync();
        AnalyticsService.Instance.StartDataCollection();

        try
        { 
            // For 3.0.1-pre.1
            //PushNotificationsService.Instance.OnNotificationReceived += notificationData =>
          
            // For 4.0.0-pre.1
            PushNotificationsService.Instance.OnRemoteNotificationReceived += notificationData =>
            {
                Debug.Log("Received a notification!");
                foreach (KeyValuePair<string, object> item in notificationData)
                {
                    Debug.Log($"Notification data item: {item.Key} - {item.Value}");
                }
            };

            Debug.Log("Attempting to Register for Remote Notifications");
            string pushToken = await PushNotificationsService.Instance.RegisterForPushNotificationsAsync();
            Debug.Log($"Notification Token Received = {pushToken}");
        }
        catch (Exception e)
        {
            Debug.Log($"Failed to retrieve a push notification token. :: {e.Message}");
        }
    }

Apologies for the inconvenience this has caused, but thanks for bringing it to our attention. We will be updating the documentation with the additional configuration steps immediately.

The Mobile Notifications package also supports Local Notifications and some other additional functionality, you can find out more in the Mobile Notifications package documentation.

Updated again to 4.0.0-pre.1 and set the checkboxes as in the screenshot didn’t work. Even when enabling the checkbox for Enable Release Environemnt for APS it does not work.

When debugging inside XCode, I get a device token, however if I download from Apple TestFlight, I don’t get anything.

If you are getting a device token while debugging through XCode, it would suggest that your code and checkboxes for registering the device to receive notifications are OK.

Were you able to send a test notification from the Unity Dashboard > Push Notifications > Settings page and receive it on the device whilst testing through Xcode? If you were, it would confirm that the key you input into the notications settings page was correct and matched your build environment.

I think the issue is most likely development / production settings, capabilities or certificate related.

A few things to check:

  • Is the Development Build checkbox checked in the Editor > Build Settings page checked or not?

  • Is the Project Settings > Player > Other Settings > Automatically Sign setting checked or not, if not are you using a Development or Production certificate to sign the build?

  • I have seen posts elsewhere suggesting a production certificate is required for Testflight builds, but I haven’t validated that myself yet!*

  • There may be something in your Xcode Capabilities and Signing settings that needs to be different for TestFlight.

Please let me know if any of these pointers help you identify and resolve the issue, if not we can dig deeper into your settings and try to reproduce / resolve the issue.

TestFlight worked without issues with 3.0.1-pre.1, the issues only started with 4.0.0-pre.1. I traced the console for a device token and got one, but no registration information on a clean new install inside the analytics. Test with the messaging tool was successful (production key and certificate), however none of my configured push notifications are being sent anymore, no logs in the analytics browser, no outgoing “OutOfGameSend” notification.

Edit: It just took around twelfe hours for the registration to complete and be visible in the analytics. Everything looks good now, but waiting for some of the scheduled notifications to be sent.

We are encountering very similar issues to those described. On Unity Cloud, we are receiving the following error: “Notification failed to send. Please double-check your key configuration and the device token and try again.” We have followed the documentation carefully, but the issue persists.

Hi Rafa,

  1. Can you confirm if you can successfully Send a test message from the ‘Push Notifications Settings’ page in the Unity Dashboard and receive it on the device the token is from?

  1. If you can’t send and receive a test message, can you confirm if you are receiving a device token successfully after the app launches? Please share a screenshot of our Project Settings > Mobile Notifications configuration page from the Editor. There are 3 checkboxes that you need to make sure are enabled to receive a device token.

  1. If you are still struggling, can you confirm if you saw and agreed to receive notifications on running the app for the first time?

  2. Can you confirm if you have added the Push Notifications capability to your

  3. If you are still struggling, please check that you have uploaded your certificate and details on the Push Notifications > Settings page correctly. Pay particular attention to the Sandbox True/False setting and make sure it matches your Editor > Build Settings > Development Build setting.

If you are still struggling. Please submit a support ticket here and include details of your project, source code etc…