Permission.RequestUserPermission Freeze my game every time. Why?

Hey all,

I have the following code :

if (!Permission.HasUserAuthorizedPermission("android.permission.POST_NOTIFICATIONS")) {
            Permission.RequestUserPermission("android.permission.POST_NOTIFICATIONS");
}

When I run it (ie. called when a button was pressed)… then my game freezes. I can see the framerate basically drops to 1 at best. I can tell it has not crashed the game because if I put a Debug.Log inside an Update, I see some log messages.

Any idea why?

(I have confirmed I am not doing anything stupid like calling it many times in a loop, etc)

Hey! Did you manage to solve this? I’m having the exact same issue and I’m running out of options…

Post the exact error messages, that’s what the “experts” will ask for :smile:

And what OS is your computer? Windows? Mac? Linux? They’ll ask all that an’ all.

Are you using a Unity version older than 2020.3.42? I had this issue, and it was fixed by updating to 2020.3.42 or later. I think this is the fix note from the changelog:

Android: Fixed infinite loop when requesting for runtime permission that is automatically rejected by the OS. (UUM-15923)

I have same issue and I am in 2021.3.11f1

I can confirm this is an issue on 2021.2.15f1, though it wasn’t a problem before. I had a setup that basically turned off the game if all needed permissions weren’t given after asking for a second time, and it worked. But now the game just freezes after the first popup regardless of the option selected (deny, allow, allow always).

Some forum diving point to some obscure solutions for what appears a previous iteration of the issue, that go from updating some build settings to upgrading Unity. As far as I can tell none of these work.

same issue for me

ok, so how I have resolved this - instead of using Permission.RequestUserPermission use

#if UNITY_ANDROID
            var channel = new Unity.Notifications.Android.AndroidNotificationChannel
            {
                Id = "ch",
                Name = "Default Channel",
                Importance = Unity.Notifications.Android.Importance.None,
                Description = " notifications",
            };
            Unity.Notifications.Android.AndroidNotificationCenter.RegisterNotificationChannel(channel);
#endif

and if you are using firebase as I do you can still use

     FirebaseMessaging.RequestPermissionAsync();

which will requests permission for IOS I presume.