Unity-Technologies/com.unity.mobile.notifications

[iOS] Crash after accepting notifications

lfernandezJC opened this issue · 5 comments

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! 🥳

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

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

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.

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!

Fixed in master.