unity3D导出iOS的问题解决

第一步unity3D导出iOS工程~

如何导出iOS工程,查看网上教程~导出后的文件目录如下
id="iframe_0.6781395587604493" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://ww4.sinaimg.cn/large/7305b707jw1f4dtn1f6hlj20mm0kmjtf.jpg?_=5544502%22%20style=%22border:none;max-width:962px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.6781395587604493',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; width: 814px; height: 742px;">

第二步将一些文件导入自己的工程项目中

将Classes 和 Libraries 文件夹以 下面的方式导入自己的工程中
id="iframe_0.9122480705846101" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://ww2.sinaimg.cn/large/7305b707jw1f4dubjk5tyj214k0nwgox.jpg?_=5544502%22%20style=%22border:none;max-width:962px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.9122480705846101',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; width: 962px; height: 567px;">
将Data 文件夹以下面的方式导入工程中
id="iframe_0.3599306216929108" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://ww4.sinaimg.cn/large/7305b707jw1f4dufj55t5j214k0nwtc9.jpg?_=5544502%22%20style=%22border:none;max-width:962px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.3599306216929108',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; width: 962px; height: 567px;">

第三步删除Native下所有.h文件的引用

删除Native下所有.h文件的引用,注意里面不仅仅只有.h 文件,,还有.cpp文件
id="iframe_0.04352224920876324" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://ww3.sinaimg.cn/large/7305b707jw1f4duhu2l8dj20xc1ckdxp.jpg?_=5544502%22%20style=%22border:none;max-width:962px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.04352224920876324',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; width: 962px; height: 1401px;">
id="iframe_0.9479405493475497" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://ww4.sinaimg.cn/large/7305b707jw1f4duhukcwnj21cq0ssavj.jpg?_=5544502%22%20style=%22border:none;max-width:962px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.9479405493475497',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; width: 962px; height: 568px;">

第四步删除libil2cpp引用~

id="iframe_0.8536127945408225" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://ww3.sinaimg.cn/large/7305b707jw1f4dv0bqsdkj20uu0ze7hl.jpg?_=5544502%22%20style=%22border:none;max-width:962px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.8536127945408225',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; width: 962px; height: 1104px;">

第五步添加引用库

添加引用库,注意有三个是optional ~
id="iframe_0.8434851360507309" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://ww4.sinaimg.cn/large/7305b707jw1f4dv3fdjr3j20ir0dh76j.jpg?_=5544502%22%20style=%22border:none;max-width:962px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.8434851360507309',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; width: 675px; height: 485px;">

第六步Build Settings

id="iframe_0.9607433108612895" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://ww4.sinaimg.cn/large/7305b707jw1f4dv4qxty5j211i0kowl0.jpg?_=5544502%22%20style=%22border:none;max-width:962px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.9607433108612895',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; width: 962px; height: 530px;">

在 other Linker Flags 添加

-weak_framework CoreMotion -weak-lSystem
id="iframe_0.5532327957917005" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://ww3.sinaimg.cn/large/7305b707jw1f4dv4qjbixj21e00ucqid.jpg?_=5544502%22%20style=%22border:none;max-width:962px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.5532327957917005',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; width: 962px; height: 584px;">

在Header Search Path 添加下面这些头文件引用~

SRCROOT/../../iOS/unity2iOSSRCROOTiOSunity2iOS{SRCROOT}/../../iOS/unity2iOS/Classes
SRCROOT/../../iOS/unity2iOS/Classes/NativeSRCROOTiOSunity2iOSClassesNative{SRCROOT}/../../iOS/unity2iOS/Libraries
SRCROOT/../../iOS/unity2iOS/Libraries/libil2cpp/includeSRCROOTiOSunity2iOSLibrarieslibil2cppinclude{SRCROOT}/../../iOS/unity2iOS/Libraries/Plugins/iOS
id="iframe_0.4973437727894634" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://ww1.sinaimg.cn/large/7305b707jw1f4dvdkn61vj20uu0futh8.jpg?_=5544502%22%20style=%22border:none;max-width:962px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.4973437727894634',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; width: 962px; height: 494px;">

在Library Search Path 中添加

SRCROOT/../../iOS/unity2iOSSRCROOTiOSunity2iOS{SRCROOT}/../../iOS/unity2iOS/Libraries
${SRCROOT}/../../iOS/unity2iOS/Libraries/Plugins/iOS
id="iframe_0.2516752181109041" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://ww1.sinaimg.cn/large/7305b707jw1f4dvf3ilt8j21h40sek4p.jpg?_=5544502%22%20style=%22border:none;max-width:962px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.2516752181109041',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; width: 962px; height: 514px;">

在other C Flags 中添加 -DINIT_SCRIPTING_BACKEND=1 同是在 other C++ Flags中出现
id="iframe_0.36894727358594537" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://ww4.sinaimg.cn/large/7305b707jw1f4dvgrlopvj21460kegup.jpg?_=5544502%22%20style=%22border:none;max-width:962px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.36894727358594537',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; width: 962px; height: 488px;">

改为C99
id="iframe_0.27932394901290536" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://ww4.sinaimg.cn/large/7305b707jw1f4dvgrgvoij218i0ea455.jpg?_=5544502%22%20style=%22border:none;max-width:962px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.27932394901290536',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; width: 962px; height: 309px;">

改PCH
id="iframe_0.004447311628609896" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://ww2.sinaimg.cn/large/7305b707jw1f4dvgsbo7mj210207agop.jpg?_=5544502%22%20style=%22border:none;max-width:962px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.004447311628609896',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; width: 962px; height: 194px;">

C++做如下设置
id="iframe_0.693582811858505" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://ww1.sinaimg.cn/large/7305b707jw1f4dvl222arj213608ctbn.jpg?_=5544502%22%20style=%22border:none;max-width:962px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.693582811858505',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; width: 962px; height: 205px;">

跟着下面的图片做设置更改
id="iframe_0.5713192054536194" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://ww1.sinaimg.cn/large/7305b707jw1f4dvl1iicdj212e0d278r.jpg?_=5544502%22%20style=%22border:none;max-width:962px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.5713192054536194',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; width: 962px; height: 327px;">

在user-Defined 添加如下

GCC_THUMB_SUPPORT NO
GCC_USE_INDIRECT_FUNCTION_CALLS NO
UNITY_RUNTIME_VERSION 5.3.4f1
UNITY_SCRIPTING_BACKEND il2cpp

第七步修改PCH文件

把Classes下面的Perfix.pch中的代码全部拷贝到自己项目的PCH 并且在自己的项目的PCH 中添加 #import "UnityAppController.h"

id="iframe_0.4749271946493536" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://ww1.sinaimg.cn/large/7305b707jw1f4dvoapzyyj214a0v614h.jpg?_=5544502%22%20style=%22border:none;max-width:962px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.4749271946493536',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; width: 962px; height: 744px;">

当你走完上面七步之后,下面才是真正的坑开始的地方~ 笔者使用的是unity做Vuforia的开发,其中涉及到的坑相信大家也被坑了好久~ 不过最后笔者得出了两行代码~ 解决了一切问题~

我在unityAppController 中创建了一个Appdelegate,并且把unityView 和Window 传过去了~ 代码后面有人问到再补上~ 欢迎有遇到同样坑的小伙伴在下面提问题,笔者会定时更新文章并把解决问题附上~

你可能感兴趣的:(unity3D导出iOS的问题解决)