当前位置:   article > 正文

留个档,Unity的Xcode后处理_getunitymaintargetguid

getunitymaintargetguid
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
using UnityEngine;
  • 1
  • 2
  • 3
  • 4
[PostProcessBuild(999)]
public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
  • 1
  • 2

获取 子工程GUID

string projPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
PBXProject pbxProject = new PBXProject();
pbxProject.ReadFromString(File.ReadAllText(projPath));

pbxProject.GetUnityMainTargetGuid());
pbxProject.GetUnityFrameworkTargetGuid());
pbxProject.TargetGuidByName("Unity-iPhone Tests"));
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

设置自动签名(DEVELOPMENT_TEAM的编码可以手动设置一次Xcode后,文本打开Unity-iPhone.xcodeproj/project.pbxproj,在里面看到)

pbxProject.SetBuildProperty(strGUID, "CODE_SIGN_IDENTITY[sdk=macosx*]", "Apple Development");
pbxProject.SetBuildProperty(strGUID, "CODE_SIGN_IDENTITY", "Apple Development");
pbxProject.SetBuildProperty(strGUID, "CODE_SIGN_STYLE", "Automatic");
pbxProject.SetBuildProperty(strGUID, "DEVELOPMENT_TEAM", "ASDBFBASDA");
  • 1
  • 2
  • 3
  • 4

添加Bundle到工程

string strBundlePath = Path.Combine(pathToBuiltProject, "Frameworks/ThirdParty/SGSDK/Plugins/iOS/test.bundle");
string resourcesBuildPhase = pbxProject.GetResourcesBuildPhaseByTarget(targetGuid);
string resourcesFilesGuid = pbxProject.AddFolderReference(strBundlePath, strBundlePath, PBXSourceTree.Source);
pbxProject.AddFileToBuildSection(targetGuid, resourcesBuildPhase, resourcesFilesGuid);
  • 1
  • 2
  • 3
  • 4

设置BuildSettings内容

pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO"); 
pbxProject.SetBuildProperty(targetGuid, "ARCHS", "arm64"); 
  • 1
  • 2

添加系统库

string targetGuid = pbxProject.GetUnityFrameworkTargetGuid();
string[] arrLibrarys = new string[]
{
   "libc++.1.tbd",
   "libsqlite3.0.tbd",
   "libresolv.9.tbd",
   "SystemConfiguration.framework",
   "CoreTelephony.framework",
   "AVFoundation.framework",
   "AudioToolbox.framework",
};

// 添加framework
for (int i = 0; i < arrLibrarys.Length; i++)
{
   bool isContines = pbxProject.ContainsFramework(targetGuid, arrLibrarys[i]);
   if (!isContines)
   {
       pbxProject.AddFrameworkToProject(targetGuid, arrLibrarys[i], false);
   }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

设置mm脚本编译命令

string strGUID = pbxProject.FindFileGuidByProjectPath("Libraries/Plugins/iOS/test.mm");
pbxProject.SetCompileFlagsForFile(targetGuid, strGUID, new List<string>() { "-fno-objc-arc" });
  • 1
  • 2

设置plist

string strPList = Path.Combine(pathToBuiltProject, "Info.plist");
PlistDocument plist = new PlistDocument();
string strPListData = File.ReadAllText(strPList);
plist.ReadFromString(strPListData);
PlistElementDict rootDict = plist.root;
// 设置语言语言环境
rootDict.SetString("CFBundleDevelopmentRegion", ibd.CFBundleDevelopmentRegion.ToString());
// 权限声明
rootDict.SetString("NSCameraUsageDescription", ibd.NSCameraUsageDescription);
rootDict.SetString("NSMicrophoneUsageDescription", ibd.NSMicrophoneUsageDescription);

// 外链相关
PlistElementArray urlTypes = rootDict.CreateArray("CFBundleURLTypes");
PlistElementDict fbUrl = urlTypes.AddDict();
fbUrl.SetString("CFBundleTypeRole", "Editor");
var array = fbUrl.CreateArray("CFBundleURLSchemes");
array.AddString("fb?????????");

// 白名单
PlistElementArray queriesSchemes = rootDict.CreateArray("LSApplicationQueriesSchemes");
queriesSchemes.AddString("fb");
queriesSchemes.AddString("instagram");
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

程序学无止尽。
欢迎大家沟通,有啥不明确的,或者不对的,也可以和我私聊
我的QQ 334524067 神一般的狄狄

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

闽ICP备14008679号