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

[iOS] Crash after accepting notifications #205

Closed lfernandezJC closed 1 year ago

lfernandezJC commented 2 years ago

Hi guys! We just found that some users are experiencing a crash after accepting the notifications on iOS. The crash also happens during the authorization response to get the token (after accepting the notifications on a previous session).

This issue has low repro rate but we want to know how we can prevent this.

Info iOS only issue Notifications 2.0.1 Unity 2019.4.37f1 This issue was found on iOS versions 14 & 15. Multiple devices.

Stacktrace

il2cpp::vm::String::New(char const*) (in UnityFramework) (String.cpp:64)
ReversePInvokeWrapper_iOSNotificationsWrapper_AuthorizationRequestReceived_m654D34F7FB108ACC041CDE130B9127E31B0AFCB7 (in UnityFramework)
-[UnityNotificationManager finishAuthorization:forRequest:] (in UnityFramework) (UnityNotificationManager.m:49)
-[UnityNotificationManager finishRemoteNotificationRegistration:notification:] (in UnityFramework) (UnityNotificationManager.m:70)
__51+[UnityNotificationLifeCycleManager sharedInstance]_block_invoke_6 (in UnityFramework) (UnityAppController+Notifications.mm:91)

Debugging note: While trying to reproduce the same issue I was able to force it sending a void* to the authData->deviceToken on this part UnityNotificationManager.m#L47. I got the exact same stacktrace but Im unable to get to the real source of the issue (limited ObjC knowledge). Hope this helps with the debugging process.

Code used to force the crash:

UnityNotificationManager.m

- (void)finishAuthorization:(struct iOSNotificationAuthorizationData*)authData forRequest:(void*)request
{
  authData->deviceToken = request;
    if (self.onAuthorizationCompletionCallback != NULL && request)
        self.onAuthorizationCompletionCallback(request, *authData);
}

Thanks! 🥳

lfernandezJC commented 2 years ago

Hey guys, any news on this? The issue still persists in production. 🤔

hgonzalezsgn commented 2 years ago

hi guys is happening to us too, could you please fix? 🙏

Ivanvv commented 1 year ago

Hi, guys, I found how to fix this bug but I don't have write permissions to submit pull request. You need to modify the file UnityNotificationManager.m on line 55 insert this: authData.deviceToken = NULL; so it will look like this: image

The problem was that authData.deviceToken stays uninitialized (points to random address) if authorization failed and app crashes trying to marshal it back to managed code.

lfernandezJC commented 1 year ago

Since we're unable to consistently reproduce it I can't say that this fixes our issue, but it makes sense.

We will modify this manually and get back to this thread if we see less crashes.

Thank you!

aurimasc commented 1 year ago

Fixed in master.