Kamis, 14 Maret 2019

Unity to iOS, info.plist Overwritten After PostProcessBuild

Background:

  1. Using Unity 2018.3.5f1 to build iOS Project
  2. Using PostProcessBuild Attribute to change info.plist
  3. Code worked in a different project in Unity 2018.2.1f1

I believe I'm doing what's suggested in this article: From Unity to iOS, how to perfectly automate frameworks, settings and plist?

I've confirmed that the PostBuildProcess function is called and the info.plist is changed. I log the output and it appears correct. I also saved a 2nd file in my code (info2.plist) and it contains all the changes I expect. However, the original file (info.plist) is overwritten with different values.

It seems that Unity is overwriting the info.plist file after the PostProcessBuild functions are running.

Code is placed in /Assets/Editor folder in Unity project.

Here's one of my functions:


[PostProcessBuild(1)]
public static void ChangeXcodePlist(BuildTarget buildTarget, string pathToBuiltProject)
{
if (buildTarget == BuildTarget.iOS)
{
// Get plist file and read it.
string plistPath = pathToBuiltProject + "/Info.plist";
Debug.Log("In the ChangeXCodePlist, path is: " + plistPath);
PlistDocument plist = new PlistDocument();
plist.ReadFromString(File.ReadAllText(plistPath));
Debug.Log("In the ChangeXCodePlist");

// Get root
PlistElementDict rootDict = plist.root;

// Required when using camera for demos, e.g. AR demos.
rootDict.SetString("NSCameraUsageDescription", "Uses the camera for Augmented Reality");

// Required when using photo library in demo (i.e. reading library).
rootDict.SetString("NSPhotoLibraryUsageDescription", "${PRODUCT_NAME} photo use");

// Required when adding images to photo library in demos.
rootDict.SetString("NSPhotoLibraryAddUsageDescription", "${PRODUCT_NAME} photo use");

//ITSAppUsesNonExemptEncryption, this value is required for release in TestFlight.
rootDict.SetBoolean("ITSAppUsesNonExemptEncryption", false);

Debug.Log("PLIST: " + plist.WriteToString());

// Write to file
File.WriteAllText(plistPath, plist.WriteToString());
File.WriteAllText(pathToBuiltProject + "/info2.plist", plist.WriteToString());
}
}



from Unity to iOS, info.plist Overwritten After PostProcessBuild

Unity to iOS, info.plist Overwritten After PostProcessBuild Rating: 4.5 Diposkan Oleh: Admin

0 komentar:

Posting Komentar

Popular Posts