Add Admob with Cocos2d-x on IOS(2013-02-27 14:12:00)
reproduced
Tags: C=blog&q=it&by=tag "target=" _blank "style=" text-decoration:none; Color:rgb (62,115,160); White-space:nowrap ">it |
|
1. Download AdMob, setup your account2. Add AdMob to Xcode project. You need:-Add LIBGOOGLEADMOBADS.A to bundle libraries-Create a group and add AdMob header file3.In AppController.h, add Member:
@interface AppController: NSObject <</span>uiaccelerometerdelegate, uialertviewdelegate,uitextfielddelegate , Uiapplicationdelegate, gadbannerviewdelegate> {
uiwindow *window;
rootviewcontroller *viewcontroller;
gadbannerview * bannerview_;
}
4. In appcontroller.mm
// setup AdMob
//Create A view of the standard size in the bottom of the screen.
//Available Adsize Constants is explained in GADAdSize.h.
&NBSP; Bannerview_ = [[ Gadbannerview alloc " initwithadsize : Kgadadsizebanner;
bannerview_. Delegate = self;
//Specify the ad ' s "unit identifier." This is your AdMob Publisher ID.
bannerview_. Adunitid = @ "your_id";
//Let the runtime know which Uiviewcontroller-to- Restore after taking
//The user wherever the ad goes and add it to the view hierarchy.
&NBSP; Bannerview_ Rootviewcontroller = viewcontroller
[ viewcontroller. View Addsubview :bannerview_];
//Initiate a generic request to load it with an ad.
gadrequest * adrequest = [gadrequest request];
[Bannerview_ loadrequest: adrequest];
/ /Start Game
cocos2d:: ccapplication:: sharedapplication () Run ();
5. We is not over yet!!!
You'll have exceptions if running the app now. You must does this:
(Http://stackoverflow.com/questions/12635283/admob-crashes-with-gadobjectprivate-changestate-unrecognized-selector)
-OBJC to the other Linker Flags of your application target ' s build setting:
- Click the Blue Top-level project icon in XCode
- Choose your target and go to Build Settings
- Under other Linker the Flags add
-ObjC
for both Release and Debug
Done !!!
Let's make money and go IPO:)
Add Admob with Cocos2d-x on IOS