Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Crash after accepting notifications #205

Closed
lfernandezJC opened this issue Jun 27, 2022 · 5 comments
Closed

[iOS] Crash after accepting notifications #205

lfernandezJC opened this issue Jun 27, 2022 · 5 comments

Comments

@lfernandezJC
Copy link

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
Copy link
Author

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

@hgonzalezsgn
Copy link

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

@Ivanvv
Copy link

Ivanvv commented Nov 22, 2022

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.

Ivanvv added a commit to Ivanvv/com.unity.mobile.notifications that referenced this issue Nov 22, 2022
@lfernandezJC
Copy link
Author

lfernandezJC commented Nov 23, 2022

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
Copy link
Collaborator

aurimasc commented Dec 8, 2022

Fixed in master.

@aurimasc aurimasc closed this as completed Dec 8, 2022
Needle-Mirror-Bot pushed a commit to needle-mirror/com.unity.mobile.notifications that referenced this issue Jan 12, 2023
## [2.1.1] - 2023-01-04

### Fixes:
- [Android] - No longer use DeniedAndDontAskAgain permission response, only Denied.
- [iOS] - [issue 205](Unity-Technologies/com.unity.mobile.notifications#205) Fix occasional crash when registering for push notifications.
- [iOS] - [issue 242](Unity-Technologies/com.unity.mobile.notifications#242) Fix exception when OriginalUtc key is missing in data (for example notification was scheduled using older package version).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants