Original address: http://www.cnblogs.com/U-tansuo/archive/2012/11/22/unity_ios-plugin.html
Speaking of Unity tuning iOS plugin, a lot of kinky more headache, explore this to give you a general manual.
First of all: need some OC knowledge, in OC all the interface is based on the view display, and to use the third-party iOS SDK only need to simply modify the source code, the corresponding view is added to the unity build out of the root view of the Xcode project. Maybe someone is cursing, this is not nonsense, and did not say the same, I accept frankly, because really did not work.
Here are some examples to analyze: First of all to understand unity issued to Xcode project structure.
Note the red and green boxes, where the red box is useless and can be ignored. Focus on the Green box, Uiapplicationmain (argc, argv, nil, @ "AppController"); it is the entrance to the program, the general Xcode project is Uiapplicationmain (argc, argv, nil, @ "Xxxappdelegete"); Indicates a method to enter the Xxxappdelegete. This article will go into the APPCONTROLLER.M (BOOL) Application: (uiapplication*) application didfinishlaunchingwithoptions: ( nsdictionary*) in the Launchoptions method. Why go into this method, OC rules (you can see the relevant documents yourself, I was added breakpoints to see).
2, (BOOL) application: (uiapplication*) application will call [self startunity:application]; Enter the Startunity method, this method will eventually come to Openeagl_unitycallback, this is our focus. The following is the core code in this function:
_window = [[UIWindow alloc] initwithframe:rect];//Create main window
eaglview* view = [[Eaglview alloc] initwithframe:rect];//Create root view
#ifdef __IPHONE_6_0
Unityviewcontroller *controller = _ios60ornewer? [[Unityviewcontroller_ios6 alloc] init]: [[[Unityviewcontroller_preios6 alloc] init];
#else
Unityviewcontroller *controller = [[Unityviewcontroller alloc] init];
#endif
[_window addsubview:view];//Root View added to main window
if ([_window respondstoselector: @selector (Rootviewcontroller)])
{
_window.rootviewcontroller = Controller;
}
So any other third-party SDK, almost all to add his view to the root view, when the above function is executed, the root view, the main window exists now you can do whatever you want.
With a simple demo, we hope to understand the help.
Mango SDK calls Mangguocontroller.h#import <UIKit/UIKit.h> #import "AdMoGoDelegateProtocol.h" #import "AdMoGoView.h" # Import "AdMoGoWebBrowserControllerUserDelegate.h" @interface mangguocontroller:nsobject<admogodelegate, admogowebbrowsercontrolleruserdelegate>{Admogoview *largead;} @property (Nonatomic,retain) UIView *view, @endMangGuoController. M#import "MangGuoController.h" #import < Quartzcore/quartzcore.h> @implementation mangguocontroller@synthesize view;-(ID) init{self=[super init]; if (self) {UIWindow *window= [[uiapplication sharedapplication] keywindow];//get main window Self.view=[win Dow.subviews objectatindex:0]; get root view
Largead = [[Admogoview alloc] initwithappkey:@ "Mango ID" adtype:adviewtypenormalbanne R Expressmode:no Admogoviewdelegate:self]; Largead.adwebbrowswerdelegate = self; Largead.frame=cgrectzero; [Self.view addsubview:largead];//adds a mango view to the root view. [Largead release]; } return self;}
by mangguocontroller* Mg=[[mangguocontroller Alloc]init]; [MG release]; To invoke the ad. In particular, the preceding instantiation is best written like this:
-(BOOL) Application: (uiapplication*) Application didfinishlaunchingwithoptions: (nsdictionary*) launchOptions
{
Printf_console ("-applicationdidfinishlaunching () \ n");
[The root View and main window will not be instantiated until the self startunity:application];//executes
mangguocontroller* Mg=[[mangguocontroller alloc]init];//Ensure root view and main window are present
[MG release];
return NO;
}
I am also halfway decent oc beginner, the word between the lines of inappropriate places, but also to everyone more advice.
UIApplication Knowledge Points: http://johnlv.blog.sohu.com/185994960.html