由于iOS中引入各个静态SDK时,需要引入系统的一些framework和lib,如果每次打包后都手动引入、修改,会很耗时也容易出错,所以就有了本篇文章


很多都可以在unity层去设置,例如Info.plist文件,build setting,引入系统库,甚至可以修改oc层面的code 基本的操作就在下面,Talk is cheap, show me the code.

                                
                            
                                public class iOSPostProcessBuild

{

[PostProcessBuild]

    public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuildProject)

    {

        if (buildTarget != BuildTarget.iOS) {

            return;

        }

        string proPath = pathToBuildProject + "/Unity-iPhone.xcodeproj/project.pbxproj";

        PBXProject project = new PBXProject();

        project.ReadFromFile(proPath);

        string targetGuid = project.TargetGuidByName("Unity-iPhone");

        project.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-ObjC");

        project.AddFrameworkToProject(targetGuid, "libxml2.2.tbd", false);

        project.WriteToFile(proPath);



        string plistPath = Path.Combine(pathToBuildProject, "Info.plist");

        PlistDocument plist = new PlistDocument();

        plist.ReadFromFile(plistPath);

        PlistElementDict rootDic = plist.root;

        PlistElement nspel;

        if (!rootDic.values.TryGetValue("", out nspel))

        {

            rootDic.SetString("abc", "");

        }

        if (!rootDic.values.TryGetValue("def", out nspel))

        {

            rootDic.SetString("def", "ghi");

        }

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

        project.WriteToFile(proPath);

    }

}


                            

只要用心看一下上面的code,相信大家就会明白 但要说的一点是,引入libxml2.2.tbd,因为有些framework供应商提供的文档上写的是引入libxml2.tbd,但此时如果在这里也这样写就不会成功,只能加到项目navigation的引入,link binary with libraries 里面并不会有,这是因为libxml2.tbd 是libxml2.2.tbd的软链如图: