Search Unity

Permission.RequestUserPermission Freeze my game every time. Why?

Discussion in 'Getting Started' started by Sparticus, Dec 31, 2022.

  1. Sparticus

    Sparticus

    Joined:
    Mar 15, 2014
    Posts:
    149
    Hey all,

    I have the following code :

    Code (CSharp):
    1. if (!Permission.HasUserAuthorizedPermission("android.permission.POST_NOTIFICATIONS")) {
    2.             Permission.RequestUserPermission("android.permission.POST_NOTIFICATIONS");
    3. }
    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)
     
  2. rdmont

    rdmont

    Joined:
    Sep 10, 2021
    Posts:
    3
    Hey! Did you manage to solve this? I'm having the exact same issue and I'm running out of options...
     
  3. RichAllen2023

    RichAllen2023

    Joined:
    Jul 19, 2016
    Posts:
    1,026
    Post the exact error messages, that's what the "experts" will ask for :D

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

    jovanovskij

    Joined:
    Jul 25, 2017
    Posts:
    1
    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)
     
  5. rlogan

    rlogan

    Joined:
    Oct 2, 2013
    Posts:
    16
    I have same issue and I am in 2021.3.11f1
     
  6. heisarzola

    heisarzola

    Joined:
    Oct 6, 2014
    Posts:
    10
    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.
     
  7. agentdalecoper

    agentdalecoper

    Joined:
    Aug 9, 2018
    Posts:
    4
    same issue for me
     
  8. agentdalecoper

    agentdalecoper

    Joined:
    Aug 9, 2018
    Posts:
    4
    ok, so how I have resolved this - instead of using
    Permission.RequestUserPermission
    use

    Code (CSharp):
    1.  
    2. #if UNITY_ANDROID
    3.             var channel = new Unity.Notifications.Android.AndroidNotificationChannel
    4.             {
    5.                 Id = "ch",
    6.                 Name = "Default Channel",
    7.                 Importance = Unity.Notifications.Android.Importance.None,
    8.                 Description = " notifications",
    9.             };
    10.             Unity.Notifications.Android.AndroidNotificationCenter.RegisterNotificationChannel(channel);
    11. #endif
    12.  
    and if you are using firebase as I do you can still use
    Code (CSharp):
    1.          
    2.      FirebaseMessaging.RequestPermissionAsync();
    3.  
    which will requests permission for IOS I presume.