Can not change " NSPhotoLibraryUsageDescription / NSPhotoLibraryAddUsageDescription" in postbuildprocess
Hi,
I have a very strange thing going on. In a post build process i will change the NSCameraUsageDescription/NSMicrophoneUsageDescription in what ever i want from script. But when i want to change the NSPhotoLibraryAddUsageDescription (this one is not in Player Settings) setting in the info.plist file from script it is not changed when i build/run the app in Xcode.
The NSPhotoLibraryAddUsageDescription can not be set in Unity Player Settings so i need to do it from code. Offcourse when i change the NSPhotoLibraryAddUsageDescription in Xcode by hand it works but i like to do it from a post build process.
I hope someone can help me with this one ...
Greetings,
Mark
My code looks like:
using UnityEditor; using UnityEditor.Callbacks; using UnityEngine; using System.IO; using UnityEditor.iOS.Xcode;
public static class MyBuildPostprocessor { [PostProcessBuild(0)] public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject) { Debug.Log("OnPostProcessBuild started ...");
if (target == BuildTarget.iOS)
{
// Get plist
string plistPath = pathToBuiltProject + "/Info.plist";
PlistDocument plist = new PlistDocument();
plist.ReadFromString(File.ReadAllText(plistPath));
// Get root
PlistElementDict rootDict = plist.root;
// Change value of NSCameraUsageDescription in Xcode plist
var buildKey = "NSCameraUsageDescription";
rootDict.SetString(buildKey, "This description is created from code");
Debug.Log("NSCameraUsageDescription changed.");
//Change value of NSPhotoLibraryAddUsageDescription in Xcode plist
buildKey = "NSPhotoLibraryAddUsageDescription";
rootDict.SetString(buildKey, "Photo library ADD usage description changed from code.");
Debug.Log("NSPhotoLibraryAddUsageDescription changed.");
// Change value of NSPhotoLibraryUsageDescription in Xcode plist
var buildKey = "NSMicrophoneUsageDescription";
rootDict.SetString(buildKey, "This description is created from code");
Debug.Log("NSMicrophoneUsageDescription changed.");
// Write to file
File.WriteAllText(plistPath, plist.WriteToString());
}
}
}
Answer by developersice · Oct 30, 2017 at 11:02 AM
Same issue here with a sharing function, right pain having to do it manually everytime we build the app
Answer by IMD · May 02, 2019 at 04:56 PM
It's working for me... perhaps ensure this is executed last, after plugin post-processors by updating the order of execution using the attribute parameter : [PostProcessBuild(99)].
For example:
[PostProcessBuild(99)]
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) {
if (target == BuildTarget.iOS) {
OnPostprocessBuildIOS(pathToBuiltProject);
}
}
Best, Isaac
Your answer
Follow this Question
Related Questions
Why does Apple think my Unity project is trying to access the camera? 6 Answers
Unity xCode-proj all Capabilities are disabled by default after updating to Version 8.3 (8E162) 1 Answer
UNET: Network [Command] from non-player object 0 Answers
error CS0234: The type or namespace name `IActiveBuildTargetChanged 3 Answers
Texture tilling problem on iOS 2 Answers