Unity-Technologies / com.unity.mobile.notifications

Mobile Notifications Package
https://docs.unity3d.com/Packages/com.unity.mobile.notifications@2.1/manual/index.html
Other
131 stars 42 forks source link

Game crashes on IOS after enabling push notifications. #319

Closed ScottasM closed 4 months ago

ScottasM commented 4 months ago

For android I had this script setup for mobile push notifications :

void Start()
{
    DontDestroyOnLoad(gameObject);
    startNotifs();
}

private async void startNotifs()
{
    try {
        AppleManager.instance.AppendAppleLog("reached 1");
        await UnityServices.InitializeAsync();
        AppleManager.instance.AppendAppleLog("reached 2");
        bool userGaveConsent = true;

        if (userGaveConsent) {
            AnalyticsService.Instance.StartDataCollection();
        }
        AppleManager.instance.AppendAppleLog("reached 3");

        try {
            AppleManager.instance.AppendAppleLog("reached 4");
            string pushToken = await PushNotificationsService.Instance.RegisterForPushNotificationsAsync();
            AppleManager.instance.AppendAppleLog("push notif token : " + pushToken);
        }
        catch (Exception e) {
            AppleManager.instance.AppendAppleLog("Failed to retrieve a push notification token. " + e);

        }
    }
    catch (Exception e) {
        AppleManager.instance.AppendAppleLog("Failed push notif setup : " + e);
    }

}

The AppendAppleLog is my own way of logging for ios on my ubuntu vps, you can imagine it as Debug.Log

For android it works perfectly. On IOS it didnt work, all I could get was to "reached 4" and then nothing, the try catch blocks don't continue, i get no errors. I realised that in xCode project the Push notifications in signing and capabilities wasn't added. After adding it and testing the game through testflight, the game crashes either immediately on launch or after pressing allow for push notifications.

On unity cloud the project seems to be setup correctly with apple keys added and sandbox turned on.

I could reproduce this on Iphone X and iphone XS. Unity version : 2022.3.10f1 push notifications package version : 3.0.1-pre.1 Xcode version : 15.3

Here is the crash log:

Incident Identifier: 1062FD79-E5F9-4E90-B216-EF042CEFA566
Hardware Model:      iPhone10,6
Process:             Drop Down [450]
Path:                /private/var/containers/Bundle/Application/.../Drop Down.app/Drop Down
Identifier:          com.skytila.dropdown
Version:             1.4.7 (25)
AppStoreTools:       15E204
AppVariant:          1:iPhone10,6:16
Beta:                YES
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           com.skytila.dropdown [465]

Date/Time:           2024-04-27 19:51:47.8578 +0300
Launch Time:         2024-04-27 19:51:44.6379 +0300
OS Version:          iPhone OS 16.7.5 (20H307)
Release Type:        User
Baseband Version:    6.01.01
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Codes: 0x0000000000000001, 0x0000000000000000
VM Region Info: 0 is not in any region.  Bytes before following region: 4363976704
      REGION TYPE                 START - END      [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                   1041d0000-1041d4000 [   16K] r-x/r-x SM=COW  ...app/Drop Down
Triggered by Thread:  0

Thread 0 name:
Thread 0 Crashed:
0   ???                             0x0000000000000000 0x0 + 0
1   CoreFoundation                  0x00000001a91747d8 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 140 (CFNotificationCenter.c:661)
2   CoreFoundation                  0x00000001a92110c0 ___CFXRegistrationPost_block_invoke + 84 (CFNotificationCenter.c:175)
3   CoreFoundation                  0x00000001a91f58a8 _CFXRegistrationPost + 404 (CFNotificationCenter.c:201)
4   CoreFoundation                  0x00000001a9187eec _CFXNotificationPost + 680 (CFNotificationCenter.c:1193)
5   Foundation                      0x00000001a35211c4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 88 (NSNotification.m:518)
6   UnityFramework                  0x000000010c10a268 0x10a41c000 + 30335592
7   UIKitCore                       0x00000001abd6b560 __63-[UIApplication pushRegistry:didUpdatePushCredentials:forType:]_block_invoke + 92 (UIApplication.m:14685)
8   libdispatch.dylib               0x00000001afeed7a8 _dispatch_call_block_and_release + 24 (init.c:1518)
9   libdispatch.dylib               0x00000001afeee780 _dispatch_client_callout + 16 (object.m:560)
10  libdispatch.dylib               0x00000001afecfe10 _dispatch_main_queue_drain + 888 (queue.c:7794)
11  libdispatch.dylib               0x00000001afecfa88 _dispatch_main_queue_callback_4CF$VARIANT$armv81 + 36 (queue.c:7954)
12  CoreFoundation                  0x00000001a91d19ac __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 (CFRunLoop.c:1780)
13  CoreFoundation                  0x00000001a91b5648 __CFRunLoopRun + 2080 (CFRunLoop.c:3147)
14  CoreFoundation                  0x00000001a91b9d20 CFRunLoopRunSpecific + 584 (CFRunLoop.c:3418)
15  GraphicsServices                0x00000001e1285998 GSEventRunModal + 160 (GSEvent.c:2196)
16  UIKitCore                       0x00000001ab44c80c -[UIApplication _run] + 868 (UIApplication.m:3782)
17  UIKitCore                       0x00000001ab44c484 UIApplicationMain + 312 (UIApplication.m:5372)
18  UnityFramework                  0x000000010c10eb40 0x10a41c000 + 30354240
19  Drop Down                       0x00000001041d412c main + 60 (main.mm:26)
20  dyld                            0x00000001c6970344 start + 1860 (dyldMain.cpp:1165)

In xcode viewing the stack trace, this is the last place i can view :

void AppController_SendNotificationWithArg(NSString* name, id arg)
{
    [[NSNotificationCenter defaultCenter] postNotificationName: name object: GetAppController() userInfo: arg];
}
aurimasc commented 4 months ago

Wrong place. Push Notification is a separate package. Please report a bug using Unity Editor.