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)
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 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.