using UnityEditor; using UnityEngine; using UnityEditor.Callbacks; using System.IO; using System.Collections; using System.Collections.Generic; using UnityEditor.iOS.Xcode; public class NewBehaviourScript { [PostProcessBuild(100)] public static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath) { if (buildTarget != BuildTarget.iOS) { return; } string projectPath = PBXProject.GetPBXProjectPath(buildPath); PBXProject project = new PBXProject(); project.ReadFromFile(projectPath); string target = project.TargetGuidByName("Unity-iPhone"); //关闭BitCode project.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); //添加引用库 //string targetGuid = project.TargetGuidByName("Unity-iPhone"); //project.AddFrameworkToProject(targetGuid, "libc++.tbd", false); //project.AddFrameworkToProject(targetGuid, "libz.tbd", false); //project.AddFrameworkToProject(targetGuid, "SystemConfiguration.framework", false); //project.AddFrameworkToProject(targetGuid, "CoreTelephony.framework", false); //project.AddFrameworkToProject(targetGuid, "QuartzCore.framework", false); //project.AddFrameworkToProject(targetGuid, "CoreText.framework", false); //project.AddFrameworkToProject(targetGuid, "CoreGraphics.framework", false); //project.AddFrameworkToProject(targetGuid, "UIKit.framework", false); //project.AddFrameworkToProject(targetGuid, "Foundation.framework", false); //project.AddFrameworkToProject(targetGuid, "CFNetwork.framework", false); //project.AddFrameworkToProject(targetGuid, "CoreMotion.framework", false); //project.AddFrameworkToProject(targetGuid, "AlipaySDK.framework", false); //project.AddFrameworkToProject(targetGuid, "Security.framework", false); //App名称本地化 string plistPath = Path.Combine(buildPath, "Info.plist"); PlistDocument plist = new PlistDocument(); plist.ReadFromFile(plistPath); //plist.root.SetString("CFBundleDisplayName", "${CFBundleDisplayName}"); FileUtil.CopyFileOrDirectory(Application.dataPath + "/AppleDependency", buildPath + "/AppleDependency"); project.AddFileToBuild(target, project.AddFile(buildPath + "/AppleDependency/InfoPlist.strings", "InfoPlist.strings", PBXSourceTree.Source)); //修改UnityAppController.mm //string scriptPath = buildPath + "/Classes/UnityAppController.mm"; //List lines = new List(); //StreamReader streamReader = new StreamReader(scriptPath); //while (!streamReader.EndOfStream) //{ // lines.Add(streamReader.ReadLine()); //} //streamReader.Close(); //lines.Insert // ( // 0, // "#import " // ); //lines.Insert // ( // 231, // "if ([url.host isEqualToString:@\"safepay\"]) {\n" + // "//跳转支付宝钱包进行支付,处理支付结果\n" + // "[[AlipaySDK defaultService] processOrderWithPaymentResult: url standbyCallback:^ (NSDictionary * resultDic) {\n" + // "NSLog(@\"result 1 = %@\", resultDic);\n" + // " }];\n" + // "}\n" // ); //lines.Insert // ( // 247, // "// NOTE: 9.0以后使用新API接口\n" + // "-(BOOL)application:(UIApplication*)app openURL: (NSURL*)url options: (NSDictionary*)options\n" + // "{\n" + // "if ([url.host isEqualToString: @\"safepay\"])\n" + // "{\n" + // "//跳转支付宝钱包进行支付,处理支付结果\n" + // "[[AlipaySDK defaultService]\n" + // "processOrderWithPaymentResult:url standbyCallback:^(NSDictionary* resultDic) {\n" + // "NSLog(@\"result 2 = %@\", resultDic);\n" + // "}];\n" + // "}\n" + // "return YES;\n" + // "}\n" // ); //StreamWriter streamWriter = new StreamWriter(scriptPath); //for (int i = 0; i < lines.Count; i++) //{ // streamWriter.WriteLine(lines[i]); //} //streamWriter.Close(); //添加URLScheme //PlistElementDict urlDict = plist.root["CFBundleURLTypes"].AsArray().AddDict(); //PlistElementArray urlArray = urlDict.CreateArray("CFBundleURLSchemes"); //urlArray.AddString("MyLovelyGarden"); //保存Plist plist.WriteToFile(plistPath); //保存PBXProject File.WriteAllText(projectPath, project.WriteToString()); } }