Unity到iOS,info.plist在PostProcessBuild之后被覆盖

问题描述 投票:2回答:1

背景:

  1. 使用Unity 2018.3.5f1构建iOS项目
  2. 使用PostProcessBuild属性更改info.plist
  3. 代码在Unity 2018.2.1f1中的另一个项目中工作

我相信我正在做本文中的建议:From Unity to iOS, how to perfectly automate frameworks, settings and plist?

我已经确认调用了PostBuildProcess函数并且更改了info.plist。我记录输出,看起来是正确的。我还在我的代码(info2.plist)中保存了第二个文件,它包含了我期望的所有更改。但是,原始文件(info.plist)将被不同的值覆盖。

在PostProcessBuild函数运行后,Unity似乎覆盖了info.plist文件。

代码放在Unity项目的/ Assets / Editor文件夹中。

这是我的一个功能:

[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());
    }
}
ios unity3d post-build-event
1个回答
4
投票

谢谢@dogiordano,这就是问题所在。一位同事在项目中添加了一个库,其中包含一个PostProcessBuild属性,没有像这样定义的调用顺序:

[PostProcessBuild]

而我的2个回调有指定的顺序: [PostProcessBuild(0)] [PostProcessBuild(1)]

文档中没有任何内容描述在这种情况下会发生什么:https://docs.unity3d.com/ScriptReference/Callbacks.PostProcessBuildAttribute.html

所以,我尝试了我的函数(1)和(2),以查看未指定的顺序是否采用(0)槽而不是。像这样: [PostProcessBuild] - 其他图书馆 [PostProcessBuild(1)] - 我的 [PostProcessBuild(2)] - 我的

因此,如果未指定回调顺序,则在指定顺序的函数之后调用这些函数。

我为所有3指定了回调顺序,它按预期工作。 [PostProcessBuild(0)] - 其他图书馆 [PostProcessBuild(1)] - 我的 [PostProcessBuild(2)] - 我的

© www.soinside.com 2019 - 2024. All rights reserved.