赞
踩
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
using UnityEngine;
[PostProcessBuild(999)]
public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
获取 子工程GUID
string projPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
PBXProject pbxProject = new PBXProject();
pbxProject.ReadFromString(File.ReadAllText(projPath));
pbxProject.GetUnityMainTargetGuid());
pbxProject.GetUnityFrameworkTargetGuid());
pbxProject.TargetGuidByName("Unity-iPhone Tests"));
设置自动签名(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");
添加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);
设置BuildSettings内容
pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
pbxProject.SetBuildProperty(targetGuid, "ARCHS", "arm64");
添加系统库
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); } }
设置mm脚本编译命令
string strGUID = pbxProject.FindFileGuidByProjectPath("Libraries/Plugins/iOS/test.mm");
pbxProject.SetCompileFlagsForFile(targetGuid, strGUID, new List<string>() { "-fno-objc-arc" });
设置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");
程序学无止尽。
欢迎大家沟通,有啥不明确的,或者不对的,也可以和我私聊
我的QQ 334524067 神一般的狄狄
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。