Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How can i trigger ios permission requests at beginning of app

Discussion in 'iOS and tvOS' started by Zikos95, Nov 7, 2017.

  1. Zikos95

    Zikos95

    Joined:
    Nov 21, 2016
    Posts:
    4
    So basicly the app requests for two permissions, for camera and access to photo library. The camera is an AR camera, i can trigger that by having a scene with the camera in it and load it at the beginning. The photo library permission popup comes up when i save a picture. The question is how can i trigger the photo library permission without having to save an image.

    Thanks in advance.
     
  2. aihodge

    aihodge

    Joined:
    Nov 23, 2014
    Posts:
    164
  3. inkredibl

    inkredibl

    Unity Technologies

    Joined:
    Nov 11, 2015
    Posts:
    21
    You can request for camera access by using RequestUserAuthorization. As for photo library access, is that some plugin that you're using?
     
  4. aihodge

    aihodge

    Joined:
    Nov 23, 2014
    Posts:
    164
    The documentation to which you linked says that RequestUserAuthorization is for Web Player. Is it interoperable with iOS permissions?
     
    ina likes this.
  5. ImDev

    ImDev

    Joined:
    Dec 24, 2015
    Posts:
    2
    Hi Any update for this question?
     
    ina likes this.
  6. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,058
    @inkredibl
    It looks like UserAuthorization only has cam and mic... What about photo album?

    Here are the plist keys. Is there a way to have these be prompted right when the app starts instead of when it's accessed?

    NSPhotoLibraryUsageDescription
    NSPhotoLibraryAddUsageDescription

    Here's a way to generate plist permissions automatically

    <pre>
    using UnityEngine;
    using UnityEditor;
    using UnityEditor.Callbacks;
    using UnityEditor.iOS.Xcode;
    using System;
    using System.IO;

    //=============================================================================
    // This PostProcessor does all annoying Xcode steps automatically for us
    //=============================================================================

    public class PostProcessor
    {
    [PostProcessBuild]
    public static void OnPostProcessBuild(BuildTarget target, string path)
    {
    if(target != BuildTarget.iOS) { return; }

    string plistPath = Path.Combine(path, "Info.plist");
    PlistDocument plist = new PlistDocument();
    plist.ReadFromString(File.ReadAllText(plistPath));

    PlistElementDict rootDict = plist.root;
    rootDict.SetString("NSPhotoLibraryUsageDescription", "Can we save your animations to your photo album?");
    rootDict.SetString("NSPhotoLibraryAddUsageDescription", "Can we save your animations to your photo album?");


    File.WriteAllText(plistPath, plist.WriteToString());
    }
    }

    </pre>
     
  7. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    260
    I need photo permissions request access as well