赞
踩
前言:unity出ios包的时候,xcode工程都需要设置一些参数,特别是接入一些第三方的SDK
的时候,需要引入一些新的库,每次出包,都需要操作一次,很麻烦,于是这算是一个自动出包的工具
主要使用类是PBXproject类
[PostProcessBuild()]
public static void OnPostProcessBuild(BuildTarget target, string xcodeprojectpath)
OnPostProcessBuild构建玩xcode工程后,回调
1.AddCapabilityToPbx 添加授限:
高于unity2017可直接使用 pbxProject.AddCapability(IPHONE_GUID,PBXCapabilityType.SignInWithApple);
我的版本校旧,使用以下方法,文件路径 xcodeprojectpath/Unity-iPhone/xxx.entitlements
- PlistDocument tempEntitlements = new PlistDocument();
- Dictionary<string, PlistElementArray> capabilityList = new Dictionary<string, PlistElementArray>();
- capabilityList[你要填的key] = (tempEntitlements.root[你要填的key] = new PlistElementArray()) as PlistElementArray;
- capabilityList[你要填的key].values.Add(new PlistElementString(你要填的Value));
- tempEntitlements.WriteToFile(xcodeprojectpath/Unity-iPhone/xxx.entitlements);
-
- ((PBXProject)pbxProject).SetBuildProperty(IPHONE_GUID, "CODE_SIGN_ENTITLEMENTS", relativeEntitlementFilePath);
list类似一个字典,下面是几个授权常用的key和value :
com.apple.developer.applesignin Default 对应signin 内购授权
keychain-access-groups id 对应钥匙串共享key授权,
这个比较特别,
aps-environment development或production 对应推送授权push notify
特别的权限 需要在info.plist添加
string UIBackground = "UIBackgroundModes";
string uibackvalue = m_platform.GetInfo(UIBackground);
if (uibackvalue != null)
{
PlistElementArray backgroudArr = dict.CreateArray(UIBackground);
backgroudArr.AddString(uibackvalue);
}
2.修改teamid和证书
pbxProject.SetBuildProperty(IPHONE_GUID, Key, Value);
一句代码,下面是key和value对应,Automatic代表自动分发证书
Key CODE_SIGN_STYLE PROVISIONING_PROFILE_SPECIFIER DEVELOPMENT_TEAM
Value Manual/Automatic 证书名 teamid
3.引入库
普通库:
fileGuid = _pbx.AddFile(path, path, PBXSourceTree.Sdk);
_pbx.AddFileToBuild(tagProGuid, fileGuid);
动态库:
fileGuid = _pbx.AddFile(path, path, PBXSourceTree.Sdk);
_pbx.AddFileToBuild(tagProGuid, fileGuid);
PBXProjectExtensions.AddFileToEmbedFrameworks(_pbx, tagProGuid, fileGuid)
添加的库需要配置searchpath选项:
framework的库使用 _pbx.AddBuildProperty(tagProGuid, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/" + 路径);
.a的库使用 _pbx.AddBuildProperty(tagProGuid, "LIBRARY_SEARCH_PATHS", "$(PROJECT_DIR)/" + 路径);
embed动态的库_pbx.SetBuildProperty(tagProGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
4.修改buildsetting
设置
pbxProject.AddBuildProperty(IPHONE_GUID,"OTHER_LDFLAGS"," -ObjC");
pbxProject.SetBuildProperty(IPHOTHER_LDFLAGSONE_GUID, VALID_ARCHS,arm64);
5.修改info.plist
- PlistDocument plist = new PlistDocument();
- string filePath = Path.Combine(SaveXcodePath, "Info.plist");
- plist.ReadFromFile(filePath);
- #region 打开设置权限
- PlistElementDict dict = plist.root.AsDict();
- PlistElementArray arrartemp = dict.CreateArray("CFBundleURLTypes");
-
- List<string> listSetURLTypees = new List<string>();
- m_platform.GetXmlSetXcodeList("Info/CFBundleURLTypes/CFBundleURLSchemes", ref listSetURLTypees);
- //Dictionary<string, PlistElementArray> URLTypesDict = new Dictionary<string, PlistElementArray>();
- foreach (var v in listSetURLTypees)
- {
- Debug.Log("sssssssssssss" + v);
- PlistElementDict dictemp = arrartemp.AddDict();
- Dictionary<string, PlistElementArray> URLTypesDict = new Dictionary<string, PlistElementArray>();
- URLTypesDict["CFBundleTypeRole"] = dictemp.CreateArray("CFBundleTypeRole");
- URLTypesDict["CFBundleTypeRole"].AddString("Editor");
- URLTypesDict["CFBundleURLSchemes"] = dictemp.CreateArray("CFBundleURLSchemes");
- URLTypesDict["CFBundleURLSchemes"].AddString(v);
- }
plist.WriteToFile(filePath);
设置xcscheme
- string filePath = Path.Combine(SaveXcodePath, "Unity-iPhone.xcodeproj/xcshareddata/xcschemes/Unity-iPhone.xcscheme");
- string content = File.ReadAllText(filePath);
- if (content.IndexOf("enableGPUValidationMode") != -1)
- return;
- int index = content.IndexOf("allowLocationSimulation");
- if (index == -1)
- {
- Logger.Error("not find allowLocationSimulation option");
- return;
- }
-
- content = content.Insert(index, "enableGPUValidationMode=\"1\" ");
- File.WriteAllText(filePath, content);
保存
string rootPath = PBXProject.GetPBXProjectPath(SaveXcodePath);((PBXProject)pbxProject).WriteToFile(rootPath);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。