1.首先我的目标是要写入图1中红色框那个,主要是用来处理UIApplicationInvalidInterfaceOrientation Supported orientations has no common orientation with the application, and [GADFullScreenAdViewController shouldAutorotate] is returning YES -[UnityAppController(Rendering) processTouchEvents]的问题的,https://www.jianshu.com/p/5ca358d29d88,可以看上面的链接有说明
2.
```
usingUnityEngine;usingSystem.Collections;usingSystem.Collections.Generic;usingSystem.IO;namespaceUnityEditor.XCodeEditor{publicpartialclassXClass:System.IDisposable{privatestring filePath;publicXClass(string fPath){filePath=fPath;if(!System.IO.File.Exists(filePath)){Debug.LogError(filePath+"路径下文件不存在");return;}}publicvoidWriteBelow(string below,string text){StreamReader streamReader=newStreamReader(filePath);string text_all=streamReader.ReadToEnd();streamReader.Close();intbeginIndex=text_all.IndexOf(below);if(beginIndex==-1){Debug.LogError(filePath+"中没有找到标致"+below);return;}intendIndex=text_all.LastIndexOf("\n",beginIndex+below.Length);text_all=text_all.Substring(0,endIndex)+"\n"+text+"\n"+text_all.Substring(endIndex);StreamWriter streamWriter=newStreamWriter(filePath);streamWriter.Write(text_all);streamWriter.Close();}publicvoidReplace(string below,string newText){StreamReader streamReader=newStreamReader(filePath);string text_all=streamReader.ReadToEnd();streamReader.Close();intbeginIndex=text_all.IndexOf(below);if(beginIndex==-1){Debug.LogError(filePath+"中没有找到标致"+below);return;}text_all=text_all.Replace(below,newText);StreamWriter streamWriter=newStreamWriter(filePath);streamWriter.Write(text_all);streamWriter.Close();}publicvoidDispose(){}}}
```
```
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEditor;usingUnityEditor.Callbacks;usingUnityEditor.iOS.Xcode;usingSystem.IO;usingSystem;usingUnityEditor.XCodeEditor;publicclassZPXCodePostProcess{#ifUNITY_EDITOR[PostProcessBuild(1000)]publicstaticvoidOnPostProcessBuild(BuildTargettarget,stringpathToBuiltProject){if(target!=BuildTarget.iOS)return;//得到xcode工程的路径stringpath=Path.GetFullPath(pathToBuiltProject);//编辑代码文件EditorCode(path);}privatestaticvoidEditorCode(stringfilePath){//读取UnityAppController.mm文件XClassUnityAppController=newXClass(filePath+"/Classes/UnityAppController.mm");//在指定代码后面增加一行代码UnityAppController.WriteBelow("#include \"PluginBase/AppDelegateListener.h\"","#import \"IOSLoader.h\"");//在指定代码后面增加一行代码UnityAppController.WriteBelow("AppController_SendNotificationWithArg(kUnityWillFinishLaunchingWithOptions, launchOptions);","\r\t [IOSLoader splashReport];");UnityAppController.WriteBelow("AppController_SendNotificationWithArg(kUnityOnOpenURL, notifData);","\r\t return [IOSLoader application:app openURL:url options:options];");UnityAppController.WriteBelow("UnityInitApplicationNoGraphics([[[NSBundle mainBundle] bundlePath] UTF8String]);","\r\t [IOSLoader application:application DidFinishLaunchingWithOptions:launchOptions];");UnityAppController.WriteBelow("- (void)applicationDidEnterBackground:(UIApplication*)application\n{","\r\t [IOSLoader applicationDidEnterBackground:application];");UnityAppController.WriteBelow("- (void)applicationWillEnterForeground:(UIApplication*)application\n{","\r\t [IOSLoader applicationWillEnterForeground:application];");UnityAppController.WriteBelow("- (void)applicationDidBecomeActive:(UIApplication*)application\n{","\r\t [IOSLoader applicationDidBecomeActive:application];");UnityAppController.WriteBelow(" SensorsCleanup();\n}","- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler \r{\r\t return [IOSLoader application:application continueUserActivity:userActivity restorationHandler:restorationHandler];\r}");}#endif}
```
这里我之前主要是参考https://www.jianshu.com/p/366110eb1610来编写的