Search Unity

NEED HELP - iOS camera permission disclaimer

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

  1. Ohyouknow

    Ohyouknow

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

    I have a question. I'm a beginner and I'm struggling to figure out something that I'm sure is super simple for most of you.

    I'm trying to destroy a button that I press in the main menu, so that it's gone for good, after the user has pressed "ok".

    The button right now is a disclaimer letting the person know they need to "Allow" the camera permission so that the AR app will work. I'm having no issues with the button working and disappearing (using gameobject.setactive), and with it launching the iOS permission disclaimer. The issue is, once I'm back in the main menu or if I quit and re-open the app, the message/button I created is back on the page. It's ineffective at this point since the user would have clicked "allow", so its just there.

    How can I make sure once "ok" is pressed, it's gone for good and its saved no matter the user quitting or coming back to the main menu.

    Again I'm a noob. I've literally tried and googled for hours to no avail. If someone can help, I'd appreciate it.

    @Yury-Habets any chance you could assist with this?
     
  2. MrMatthias

    MrMatthias

    Joined:
    Sep 18, 2012
    Posts:
    191
    you can use the player prefs to save and read whether the user has seen that disclaimer. You can put this into the awake method of that button logic:
    Code (CSharp):
    1.         if (PlayerPrefs.GetInt("PERMISSION_DIALOG_SHOWN", 0) != 0)
    2.         {
    3.             gameObject.SetActive(false);
    4.         }
    for saving run this code:
    Code (CSharp):
    1. PlayerPrefs.SetInt("PERMISSION_DIALOG_SHOWN", 1);
     
    Ohyouknow likes this.
  3. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    To add, it wouldn't hurt to add PlayerPrefs.Save() after PlayerPrefs.SetInt(). This will ensure that the dialog will not come back, even in the event of a crash.
     
    Ohyouknow likes this.
  4. Ohyouknow

    Ohyouknow

    Joined:
    Oct 23, 2013
    Posts:
    121
    Hi @MrMatthias and @_Daniel_

    Thank you both for the help! It's working exactly how I wanted! Just to confirm, I wanted to post the code and make sure it's what you both were advising to do. Obviously the results are perfect, but I just want to be sure.

    using UnityEngine;

    public class Permissiondialogue : MonoBehaviour
    {

    void Awake()
    {
    if (PlayerPrefs.GetInt("Permissiondialogue", 0) != 0)
    {
    gameObject.SetActive(false);
    }

    PlayerPrefs.SetInt("Permissiondialogue", 1);
    PlayerPrefs.Save();
    }
    }

    The only thing I have left to do now is figure out how to make another message pop up, if the user presses "deny". Other than that, everything is perfect! Thank you so much for the help!
     
    User340 likes this.