|  |  | 
 |  |  | using System.IO; | 
 |  |  | using UnityEditor; | 
 |  |  | using UnityEditor.iOS.Xcode.Custom; | 
 |  |  | using UnityEditor.iOS.Xcode.Custom.Extensions; | 
 |  |  | using UnityEngine; | 
 |  |  |  | 
 |  |  | public class XCodeProjectMod | 
 |  |  | { | 
 |  |  |  | 
 |  |  | #if UNITY_IOS | 
 |  |  |     private const string CODE_SIGN_DEVELOPER = ""; | 
 |  |  |     private const string CODE_SIGN_DISTRIBUTION = ""; | 
 |  |  |     private const string PROVISIONING_DEVELOPER = ""; | 
 |  |  |     private const string PROVISIONING_DISTRIBUTION = ""; | 
 |  |  |     private const string TEAM = "5X26T385YZ"; | 
 |  |  |  | 
 |  |  | #if UNITY_IOS | 
 |  |  |     [UnityEditor.Callbacks.PostProcessBuild(999)] | 
 |  |  |     public static void OnPostprocessBuild(BuildTarget buildTarget, string path) | 
 |  |  |     { | 
 |  |  | 
 |  |  |         _project.AddFileToBuild(_targetGUID, _project.AddFile("/usr/lib/libiconv.tbd", "Frameworks/libiconv.tbd", PBXSourceTree.Sdk)); | 
 |  |  |         _project.AddFileToBuild(_targetGUID, _project.AddFile("/usr/lib/libresolv.tbd", "Frameworks/libresolv.tbd", PBXSourceTree.Sdk)); | 
 |  |  |  | 
 |  |  |         // mr_sdk | 
 |  |  |         HandleMrSDK(_project, _targetGUID); | 
 |  |  |  | 
 |  |  |         // sp_sdk | 
 |  |  |         HandleSpSDK(_project, _targetGUID); | 
 |  |  |  | 
 |  |  |         File.WriteAllText(_projectPath, _project.WriteToString()); | 
 |  |  |  | 
 |  |  |         var _capabilityMgr = new ProjectCapabilityManager(_projectPath, "game003.entitlements", PBXProject.GetUnityTargetName()); | 
 |  |  | 
 |  |  |             ModifyFile(path); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  | #endif | 
 |  |  |  | 
 |  |  |     private static void BuildPlist(string path) | 
 |  |  |     { | 
 |  |  | 
 |  |  |  | 
 |  |  |     private static void ModifyFile(string projectPath) | 
 |  |  |     { | 
 |  |  |         bool _isMr = false; | 
 |  |  |         string _mrPlistPath = Application.dataPath + "/Plugins/iOS/MyMRSDK/MRSDKInfo.plist"; | 
 |  |  |         if (File.Exists(_mrPlistPath)) | 
 |  |  |         { | 
 |  |  |             _isMr = true; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // -------------- UnityAppController.mm | 
 |  |  |         //读取UnityAppController.mm文件 | 
 |  |  |         var _xclass = new XClass(projectPath + "/Classes/UnityAppController.mm"); | 
 |  |  |  | 
 |  |  |         //在指定代码后面增加一行代码 | 
 |  |  |         _xclass.WriteBelow("#include \"PluginBase/AppDelegateListener.h\"", "#include \"UniversalSDK.h\"\n#include \"JPushService.h\""); | 
 |  |  |         _xclass.WriteBelow("#include \"PluginBase/AppDelegateListener.h\"", "#include \"UniversalSDK.h\"\n#include \"JPushService.h\"\n"); | 
 |  |  |  | 
 |  |  |         if (_isMr) | 
 |  |  |         { | 
 |  |  |             _xclass.WriteBelow("#include \"PluginBase/AppDelegateListener.h\"", "#include \"IAPManager.h\"\n"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         string newCode = "\n" + | 
 |  |  |                          "extern \"C\" void IOSMessageHandle(const char* jsonString) {\n" + | 
 |  |  | 
 |  |  |         //在指定代码后面增加一大行代码 | 
 |  |  |         _xclass.WriteBelow("[KeyboardDelegate Initialize];", newCode); | 
 |  |  |  | 
 |  |  |         if (_isMr) | 
 |  |  |         { | 
 |  |  |             _xclass.WriteBelow("[KeyboardDelegate Initialize];", "    [[IAPManager shared] startManager];\n"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         _xclass.WriteBelow("UnitySendDeviceToken(deviceToken);", "    [JPUSHService registerDeviceToken:deviceToken];"); | 
 |  |  |  | 
 |  |  |         if (_isMr) | 
 |  |  |         { | 
 |  |  |             _xclass.WriteBelow("SensorsCleanup();", "    [[IAPManager shared] stopManager];"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         newCode = "UnitySendRemoteNotification(userInfo);\n" + | 
 |  |  |             "    [JPUSHService handleRemoteNotification:userInfo];\n"; | 
 |  |  | 
 |  |  |         BuildPipeline.BuildPlayer(ClientPackage.baseLevels, GetBuildPath(), BuildTarget.iOS, BuildOptions.Il2CPP); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | #if UNITY_IOS | 
 |  |  |     [MenuItem("Build/ipa")] | 
 |  |  |     public static void BuildIPA() | 
 |  |  |     { | 
 |  |  | 
 |  |  |         _p.Start(); | 
 |  |  |         _p.WaitForExit(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private static void HandleMrSDK(PBXProject project, string targetGUID) | 
 |  |  |     { | 
 |  |  |         string _mrPlistPath = Application.dataPath + "/Plugins/iOS/MyMRSDK/MRSDKInfo.plist"; | 
 |  |  |         if (File.Exists(_mrPlistPath)) | 
 |  |  |         { | 
 |  |  |             string _fileGUID = project.AddFile(_mrPlistPath, "Frameworks/Plugins/iOS/MyMRSDK/MRSDKInfo.plist"); | 
 |  |  |             project.AddFileToBuild(targetGUID, _fileGUID); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private static void HandleSpSDK(PBXProject project, string targetGUID) | 
 |  |  |     { | 
 |  |  |         string _filePath = Application.dataPath + "/Plugins/iOS/SPYOUSDK/GDTActionSDK.framework"; | 
 |  |  |         if (Directory.Exists(_filePath)) | 
 |  |  |         { | 
 |  |  |             string _frameworkGUID = project.FindFileGuidByProjectPath("Frameworks/Plugins/iOS/SPYOUSDK/GDTActionSDK.framework"); | 
 |  |  |             PBXProjectExtensions.AddFileToEmbedFrameworks(project, targetGUID, _frameworkGUID); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | #endif | 
 |  |  |  | 
 |  |  | } |