How to integrate GoogleAdmob in cocos2d-x (Portrait mode) | Techbirds
In order to integrate the google admob to your existing project,firstly copy the following banner view classes and GoogleAdMobAdsSDK in proj.ios folder of your project
Banner View Classes
GoogleAdMobAdsSDK
After copying,the folder will look like this:
Now your project folder is ready for the integration,go to your Xcode project,open it,add these classes of banner view to your project directly by right click on project and click on “Add Files to project_name” option
For GoogleAdMobAdsSDK,add this in Frameworks folder and also make sure the following frameworks should be in your project,if not,then must add through Link Binary With Libraries option in Build Phases:
After making all above changes,the project in Xcode look like this:
Now make changes in AppController.h(inside the ios folder) class so that it will look like this:
Go to AppController.mm,and add the following lines after “@implementation AppController”
@synthesize window; @synthesize viewController; @synthesize bvc;
@synthesize window; @synthesize viewController; @synthesize bvc; |
and it will shown as:
Now go to function – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions inside the same class and search for the following lines:
// Set RootViewController to window if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0) { // warning: addSubView doesn’t work on iOS6 [window addSubview: viewController.view]; } else { // use this method on ios6 [window setRootViewController:viewController]; }
// Set RootViewController to window if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0) { // warning: addSubView doesn’t work on iOS6 [window addSubview: viewController.view]; } else { // use this method on ios6 [window setRootViewController:viewController]; } |
Delete these above lines and add the following bvc banner view code after the line “viewController.view = __glView;”
bvc=[[BannerViewController alloc]initWithContentViewController:viewController]; // Set RootViewController to window if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0) { // warning: addSubView doesn’t work on iOS6 [window addSubview: bvc.view]; } else { // use this method on ios6 [window setRootViewController:bvc]; }
bvc=[[BannerViewController alloc]initWithContentViewController:viewController]; // Set RootViewController to window if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0) { // warning: addSubView doesn’t work on iOS6 [window addSubview: bvc.view]; } else { // use this method on ios6 [window setRootViewController:bvc]; } |
and it will look like this:
Now,2 more imp. things left,firstly make following changes in BannerViewController.m file:
_gAdBannerView.adUnitID = @”YOUR_AD_UNIT_ID”//your admob id
_gAdBannerView.adUnitID = @”YOUR_AD_UNIT_ID”//your admob id |
Next go to function named as -(void)loadReqForAdmob:(BannerViewController*)ctrll inside the same class and change the UDID numbers as per your devices:
NSString *iPadMini = @”YOUR_UDID_NUMBER”; NSString *iPhone5 = @”YOUR_UDID_NUMBER”; NSString *iphone4 = @”YOUR_UDID_NUMBER”; NSString *ipad = @”YOUR_UDID_NUMBER”; NSString *iPod = @”YOUR_UDID_NUMBER”; NSString *iPhone = @”YOUR_UDID_NUMBER”;
NSString *iPadMini = @”YOUR_UDID_NUMBER”; NSString *iPhone5 = @”YOUR_UDID_NUMBER”; NSString *iphone4 = @”YOUR_UDID_NUMBER”; NSString *ipad = @”YOUR_UDID_NUMBER”; NSString *iPod = @”YOUR_UDID_NUMBER”; NSString *iPhone = @”YOUR_UDID_NUMBER”; |
Now run your project,if it shows some error of weak property of BannerViewController.m,then add “-fobjc-arc” in front of BannerViewController.m in Compile Sources inside the Build Phases of project TARGETS:shown as below
1,621 total views, 2 views today
Share this On