123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- 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<string> lines = new List<string>();
- //StreamReader streamReader = new StreamReader(scriptPath);
- //while (!streamReader.EndOfStream)
- //{
- // lines.Add(streamReader.ReadLine());
- //}
- //streamReader.Close();
- //lines.Insert
- // (
- // 0,
- // "#import <AlipaySDK/AlipaySDK.h>"
- // );
- //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<NSString*, id>*)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());
- }
- }
|