Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Mobile Notifications asking for location access when I manually trigger it

Discussion in 'Scripting' started by DustinKaban, Dec 10, 2021.

  1. DustinKaban

    DustinKaban

    Joined:
    Sep 14, 2012
    Posts:
    3
    When I use the mobile Notifcations settings and don't check "Include CoreLocation Framework" it works fine and doesn't prompt the user for location access.

    When I use the default code given by Unity to request access, I seem to prompt my users with a request for location access which I don't want.

    I'm using the Mobile Notifications package: https://docs.unity3d.com/Packages/com.unity.mobile.notifications@1.4/manual/index.html

    Any suggestions?

    This is the default code given by Unity:

    Code (CSharp):
    1.  IEnumerator RequestAuthorization()
    2.      {
    3.          var authorizationOption = AuthorizationOption.Alert | AuthorizationOption.Badge;
    4.          using (var req = new AuthorizationRequest(authorizationOption, true))
    5.          {
    6.              while (!req.IsFinished)
    7.              {
    8.                  yield return null;
    9.              };
    10.    
    11.              string res = "\n RequestAuthorization:";
    12.              res += "\n finished: " + req.IsFinished;
    13.              res += "\n granted :  " + req.Granted;
    14.              res += "\n error:  " + req.Error;
    15.              res += "\n deviceToken:  " + req.DeviceToken;
    16.              Debug.Log(res);
    17.          }
    18.      }