Search Unity

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

Discussion in 'Player Engagement' started by ErdionerAPDEV, Sep 26, 2023.

  1. ErdionerAPDEV

    ErdionerAPDEV

    Joined:
    Aug 30, 2023
    Posts:
    8
    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.
     
  2. jacobbev

    jacobbev

    Unity Technologies

    Joined:
    Jun 25, 2018
    Posts:
    8
    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?
     
  3. ErdionerAPDEV

    ErdionerAPDEV

    Joined:
    Aug 30, 2023
    Posts:
    8
    • 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
     
  4. vd_unity

    vd_unity

    Unity Technologies

    Joined:
    Sep 11, 2014
    Posts:
    41
    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).

    Screenshot 2023-10-03 at 08.22.36.png

    Screenshot 2023-10-03 at 08.36.25.png

    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.
    Screenshot 2023-10-03 at 08.49.06.png
    Screenshot 2023-10-03 at 08.35.15.png

    Please let us know if this helps
     
  5. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    489
    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)
     
    Last edited: Nov 8, 2023
    tkajino likes this.
  6. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    489
    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.
     
    tkajino likes this.
  7. Laurie-Unity

    Laurie-Unity

    Unity Technologies

    Joined:
    Mar 5, 2020
    Posts:
    220
    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
     
    MiTschMR likes this.
  8. tkajino

    tkajino

    Joined:
    Nov 21, 2022
    Posts:
    2
    with 2021.3.31f1 I get the same error, with andorid is ok but iOS can not get the token, So frustrating :(
     
    Last edited: Nov 11, 2023
  9. Laurie-Unity

    Laurie-Unity

    Unity Technologies

    Joined:
    Mar 5, 2020
    Posts:
    220
    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,

    Code (CSharp):
    1.    async void Start()
    2.     {
    3.         await UnityServices.InitializeAsync();
    4.         AnalyticsService.Instance.StartDataCollection();
    5.  
    6.         try
    7.         {
    8.             // For 3.0.1-pre.1
    9.             //PushNotificationsService.Instance.OnNotificationReceived += notificationData =>
    10.          
    11.             // For 4.0.0-pre.1
    12.             PushNotificationsService.Instance.OnRemoteNotificationReceived += notificationData =>
    13.             {
    14.                 Debug.Log("Received a notification!");
    15.                 foreach (KeyValuePair<string, object> item in notificationData)
    16.                 {
    17.                     Debug.Log($"Notification data item: {item.Key} - {item.Value}");
    18.                 }
    19.             };
    20.  
    21.             Debug.Log("Attempting to Register for Remote Notifications");
    22.             string pushToken = await PushNotificationsService.Instance.RegisterForPushNotificationsAsync();
    23.             Debug.Log($"Notification Token Received = {pushToken}");
    24.         }
    25.         catch (Exception e)
    26.         {
    27.             Debug.Log($"Failed to retrieve a push notification token. :: {e.Message}");
    28.         }
    29.     }
    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.
     
    vd_unity likes this.
  10. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    489
    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.
     
  11. Laurie-Unity

    Laurie-Unity

    Unity Technologies

    Joined:
    Mar 5, 2020
    Posts:
    220
    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.
     
  12. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    489
    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.
     
    Last edited: Nov 25, 2023