当前位置:   article > 正文

Unity和iOS 原生专题一 unity打包设置C#设置 Xcode添加OTHER_LDFLAGS和Info.plist设置

Unity和iOS 原生专题一 unity打包设置C#设置 Xcode添加OTHER_LDFLAGS和Info.plist设置

一、 获取 PBXProject PBXProject的很多操作都是通过guid的

var pbxProject = new PBXProject();

二 、获取projectPath

var projectPath = PBXProject.GetPBXProjectPath(iosProjectPath);

三 、读取pbxProject 文件

pbxProject.ReadFromFile(projectPath);

四 、 读取Unity-iPhone"对应的target和UnityFramework

  1. GetUnityMainTargetGuid是获取XCode工程中"Unity-iPhone"对应的target,GetUnityFrameworkTargetGuid则对应"UnityFramework"
  2. var mainTargetGuid = pbxProject.GetUnityMainTargetGuid();//
  3. //这个对应target中的Unity-iPhone
  4. var frameworkTargetGuid = pbxProject.GetUnityFrameworkTargetGuid();//
  5. //这个对应target中UnityFramework

五 、添加

  1. pbxProject.AddBuildProperty(mainTargetGuid, "OTHER_LDFLAGS", "-ObjC");
  2. pbxProject.AddBuildProperty(frameworkTargetGuid, "OTHER_LDFLAGS", "-ObjC");
  3. pbxProject.SetTeamId(mainTargetGuid, "");
  4. pbxProject.SetTeamId(frameworkTargetGuid, "");
  5. pbxProject.SetBuildProperty(mainTargetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES");
  6. pbxProject.SetBuildProperty(frameworkTargetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "NO");
  7. pbxProject.SetBuildProperty(mainTargetGuid, "GCC_ENABLE_OBJC_EXCEPTIONS", "YES");
  8. pbxProject.SetBuildProperty(frameworkTargetGuid, "GCC_ENABLE_OBJC_EXCEPTIONS", "YES");
  9. pbxProject.SetBuildProperty(mainTargetGuid, "GCC_C_LANGUAGE_STANDARD", "gnu11");
  10. pbxProject.SetBuildProperty(frameworkTargetGuid, "GCC_C_LANGUAGE_STANDARD", "gnu11");
  11. pbxProject.AddFrameworkToProject(frameworkTargetGuid, "Photos.framework", false);
  12. // info.plist 设置
  13. var plistPath = Path.Combine(iosProjectPath, "Info.plist");
  14. var plist = new PlistDocument();
  15. plist.ReadFromString(File.ReadAllText(plistPath, Encoding.ASCII));
  16. plist.root.values.Add("NSPhotoLibraryUsageDescription", new PlistElementString("We will use this permission if the child sends lessons and feedback through the album."));
  17. plist.root.values.Add("ITSAppUsesNonExemptEncryption", new PlistElementBoolean(false));
  18. AddPlistElementDict(plist,"NSAppTransportSecurity","NSAllowsArbitraryLoads",new PlistElementBoolean(true));

六、操作完后要写回文件,否则无效

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

七 、总结

  1. string pbxProjectPath = PBXProject.GetPBXProjectPath(path);
  2. pbxProject = new PBXProject();
  3. pbxProject.ReadFromString(File.ReadAllText(pbxProjectPath));
  4. mainTarget = pbxProject.GetUnityMainTargetGuid();//这个对应target中的Unity-iPhone
  5. frameworkTarget = pbxProject.GetUnityFrameworkTargetGuid();//这个对应target中UnityFramework
  6. //...
  7. //你的操作
  8. //...
  9.      pbxProject.WriteToFile(pbxProjectPath);  //操作完后要写回文件,否则无效

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/502969
推荐阅读
相关标签
  

闽ICP备14008679号