PostProcessor.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using UnityEditor;
  2. using UnityEngine;
  3. using UnityEditor.Callbacks;
  4. using System.IO;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using UnityEditor.iOS.Xcode;
  8. public class NewBehaviourScript
  9. {
  10. [PostProcessBuild(100)]
  11. public static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath)
  12. {
  13. if (buildTarget != BuildTarget.iOS)
  14. {
  15. return;
  16. }
  17. string projectPath = PBXProject.GetPBXProjectPath(buildPath);
  18. PBXProject project = new PBXProject();
  19. project.ReadFromFile(projectPath);
  20. string target = project.TargetGuidByName("Unity-iPhone");
  21. //关闭BitCode
  22. project.SetBuildProperty(target, "ENABLE_BITCODE", "NO");
  23. //添加引用库
  24. //string targetGuid = project.TargetGuidByName("Unity-iPhone");
  25. //project.AddFrameworkToProject(targetGuid, "libc++.tbd", false);
  26. //project.AddFrameworkToProject(targetGuid, "libz.tbd", false);
  27. //project.AddFrameworkToProject(targetGuid, "SystemConfiguration.framework", false);
  28. //project.AddFrameworkToProject(targetGuid, "CoreTelephony.framework", false);
  29. //project.AddFrameworkToProject(targetGuid, "QuartzCore.framework", false);
  30. //project.AddFrameworkToProject(targetGuid, "CoreText.framework", false);
  31. //project.AddFrameworkToProject(targetGuid, "CoreGraphics.framework", false);
  32. //project.AddFrameworkToProject(targetGuid, "UIKit.framework", false);
  33. //project.AddFrameworkToProject(targetGuid, "Foundation.framework", false);
  34. //project.AddFrameworkToProject(targetGuid, "CFNetwork.framework", false);
  35. //project.AddFrameworkToProject(targetGuid, "CoreMotion.framework", false);
  36. //project.AddFrameworkToProject(targetGuid, "AlipaySDK.framework", false);
  37. //project.AddFrameworkToProject(targetGuid, "Security.framework", false);
  38. //App名称本地化
  39. string plistPath = Path.Combine(buildPath, "Info.plist");
  40. PlistDocument plist = new PlistDocument();
  41. plist.ReadFromFile(plistPath);
  42. //plist.root.SetString("CFBundleDisplayName", "${CFBundleDisplayName}");
  43. FileUtil.CopyFileOrDirectory(Application.dataPath + "/AppleDependency", buildPath + "/AppleDependency");
  44. project.AddFileToBuild(target, project.AddFile(buildPath + "/AppleDependency/InfoPlist.strings", "InfoPlist.strings", PBXSourceTree.Source));
  45. //修改UnityAppController.mm
  46. //string scriptPath = buildPath + "/Classes/UnityAppController.mm";
  47. //List<string> lines = new List<string>();
  48. //StreamReader streamReader = new StreamReader(scriptPath);
  49. //while (!streamReader.EndOfStream)
  50. //{
  51. // lines.Add(streamReader.ReadLine());
  52. //}
  53. //streamReader.Close();
  54. //lines.Insert
  55. // (
  56. // 0,
  57. // "#import <AlipaySDK/AlipaySDK.h>"
  58. // );
  59. //lines.Insert
  60. // (
  61. // 231,
  62. // "if ([url.host isEqualToString:@\"safepay\"]) {\n" +
  63. // "//跳转支付宝钱包进行支付,处理支付结果\n" +
  64. // "[[AlipaySDK defaultService] processOrderWithPaymentResult: url standbyCallback:^ (NSDictionary * resultDic) {\n" +
  65. // "NSLog(@\"result 1 = %@\", resultDic);\n" +
  66. // " }];\n" +
  67. // "}\n"
  68. // );
  69. //lines.Insert
  70. // (
  71. // 247,
  72. // "// NOTE: 9.0以后使用新API接口\n" +
  73. // "-(BOOL)application:(UIApplication*)app openURL: (NSURL*)url options: (NSDictionary<NSString*, id>*)options\n" +
  74. // "{\n" +
  75. // "if ([url.host isEqualToString: @\"safepay\"])\n" +
  76. // "{\n" +
  77. // "//跳转支付宝钱包进行支付,处理支付结果\n" +
  78. // "[[AlipaySDK defaultService]\n" +
  79. // "processOrderWithPaymentResult:url standbyCallback:^(NSDictionary* resultDic) {\n" +
  80. // "NSLog(@\"result 2 = %@\", resultDic);\n" +
  81. // "}];\n" +
  82. // "}\n" +
  83. // "return YES;\n" +
  84. // "}\n"
  85. // );
  86. //StreamWriter streamWriter = new StreamWriter(scriptPath);
  87. //for (int i = 0; i < lines.Count; i++)
  88. //{
  89. // streamWriter.WriteLine(lines[i]);
  90. //}
  91. //streamWriter.Close();
  92. //添加URLScheme
  93. //PlistElementDict urlDict = plist.root["CFBundleURLTypes"].AsArray().AddDict();
  94. //PlistElementArray urlArray = urlDict.CreateArray("CFBundleURLSchemes");
  95. //urlArray.AddString("MyLovelyGarden");
  96. //保存Plist
  97. plist.WriteToFile(plistPath);
  98. //保存PBXProject
  99. File.WriteAllText(projectPath, project.WriteToString());
  100. }
  101. }