Search Unity

Help Appreciated! - iOS Permissions if disabled manually

Discussion in 'iOS and tvOS' started by Ohyouknow, Oct 21, 2018.

  1. Ohyouknow

    Ohyouknow

    Joined:
    Oct 23, 2013
    Posts:
    129
    Hi all,

    I have everything covered with my permissions except one thing.

    My AR app uses the camera. I have a custom warning that shows up before the Apple permission request. No issues there. If someone selects "Don't Allow", the game will not work until they enable manually. No issues there.

    My issue: Once they have enabled permissions or selected "Ok" form the get go, the app works without any problems unless for some reason the user decides to go back to permissions and disable it. Dumb issue, but its literally the only thing keeping my app from being approved. Apple has gone out of their way to give me this headache.

    Solution I'm looking for: I want to add code somewhere in my script that would make the custom message I have show back up if a user decides to go to the camera permissions and manually disable it. I want the app to pretty much not work, as if they've denied permissions from the get go. There must be a way to catch or check if permissions has been disabled.

    Code I'm currently using:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3.  
    4. public class UsageSample : MonoBehaviour
    5. {
    6.     // Link UI elements in the Inspector.
    7.     [SerializeField] private Button _button;
    8.  
    9.     private void Awake()
    10.     {
    11.         if (PlayerPrefs.GetInt("Permissiondialogue", 0) != 0)
    12.         {
    13.             gameObject.SetActive(false);
    14.         }
    15.     }
    16.  
    17.     void VerifyPermission()
    18.     {
    19.         // Disable the button while verifying permission.
    20.         if (_button != null) _button.interactable = false;
    21.  
    22.         // Use native UI to request camera permission.
    23.         iOSCameraPermission.VerifyPermission(gameObject.name, "SampleCallback");
    24.     }
    25.  
    26.     private void SampleCallback(string permissionWasGranted)
    27.     {
    28.         if (permissionWasGranted == "true")
    29.         {
    30.             // You can now use the device camera.
    31.             Destroy(_button.gameObject);
    32.             PlayerPrefs.SetInt("Permissiondialogue", 1);
    33.             PlayerPrefs.Save();
    34.         }
    35.         else
    36.         {
    37.             // You may want to re-enable the button to display the Settings message again.
    38.             if (_button != null) _button.interactable = true;
    39.         }
    40.     }
    41. }
     
  2. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    You may consider using the IOS Native Pro plugin.
    That is the flow you may use.
    1. Check current permissions state:
    Code (CSharp):
    1. using SA.iOS.AVFoundation;
    2. ...
    3. ISN_AVAuthorizationStatus status;
    4. status = ISN_AVCaptureDevice.GetAuthorizationStatus(ISN_AVMediaType.Video);
    5. Debug.Log("Camera Authorization Status: " + status);
    2. Analyze the ISN_AVAuthorizationStatus response. Status options:
    Code (CSharp):
    1. namespace SA.iOS.AVFoundation
    2. {
    3.     /// <summary>
    4.     /// Constants that provide information regarding permission to use media capture devices.
    5.     /// </summary>
    6.     public enum ISN_AVAuthorizationStatus
    7.     {
    8.         /// <summary>
    9.         /// Explicit user permission is required for media capture,
    10.         /// but the user has not yet granted or denied such permission.
    11.         /// </summary>
    12.         NotDetermined = 0,
    13.  
    14.         /// <summary>
    15.         /// The user is not allowed to access media capture devices.
    16.         /// </summary>
    17.         Restricted = 1,
    18.  
    19.         /// <summary>
    20.         /// The user has explicitly denied permission for media capture.
    21.         /// </summary>
    22.         Denied = 2,
    23.  
    24.         /// <summary>
    25.         /// The user has explicitly granted permission for media capture,
    26.         /// or explicit user permission is not necessary for the media type in question.
    27.         /// </summary>
    28.         Authorized = 3
    29.     }
    30. }

    3. In case status is NotDetermined start the native dialog to request the permission
    Code (CSharp):
    1. using SA.iOS.AVFoundation;
    2. ...
    3. ISN_AVCaptureDevice.RequestAccess(ISN_AVMediaType.Video, (status) => {
    4.     if(status == ISN_AVAuthorizationStatus.Authorized) {
    5.         Debug.Log("user has granted camera permission");
    6.     } else {
    7.         Debug.Log("uAVMediaType.Video Permission declined");
    8.     }
    9. });
    I believe this is what you need.
     
    Ohyouknow likes this.
  3. Ohyouknow

    Ohyouknow

    Joined:
    Oct 23, 2013
    Posts:
    129
    The above code and plugin solved my issues. Thank you!
     
  4. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    That's very good to know.