Search Unity

iOS permission localization at PostProcessBuild

Discussion in 'iOS and tvOS' started by kodekq, Nov 12, 2020.

  1. kodekq

    kodekq

    Joined:
    Sep 27, 2014
    Posts:
    23
    We needed localization of ios permissions (such as NSUserTrackingUsageDescription, NSLocationWhenInUseUsageDescription, etc.). This does not cause problems directly from xcode. You need to create a file InfoPlist.strings, select the required localizations for it and set the localization keys with translate.

    But I need to do it automatically at the PostProcessBuild stage. I tried to take directly created localization directories (such as en.lproj) and then add them to the project using
    PBXProject.AddFile and AddFileToBuild. But in this case they are added not as InfoPlist.strings, but as just "en.lproj" folders, etc. Maybe someone has done something similar. Help me please.
     
  2. kaarloew

    kaarloew

    Joined:
    Nov 1, 2018
    Posts:
    360
    Should be something like
    Code (CSharp):
    1. string plistPath = path + "/Info.plist";
    2. PlistDocument plist = new PlistDocument();
    3. plist.ReadFromFile(plistPath);
    4.  
    5. PlistElementDict rootDict = plist.root;
    6.  
    7. rootDict.SetString("NSPhotoLibraryUsageDescription", "This app requires access ...");
    8. File.WriteAllText(plistPath, plist.WriteToString());
     
  3. kodekq

    kodekq

    Joined:
    Sep 27, 2014
    Posts:
    23
    In this case, the description of the permission will not be localized.
     
  4. kaarloew

    kaarloew

    Joined:
    Nov 1, 2018
    Posts:
    360
    You have to add your own localization system there since Unity currently doesn't have localization system build-in.
     
  5. yagodar

    yagodar

    Joined:
    Oct 10, 2016
    Posts:
    17
    Look at great example https://github.com/superbderrick/UnityiOSLocalization
     
    andrew_pearce_ likes this.