c++ - why my admob doesn't show? -


there no errors in console, , seems work. bannerview_ didn't show.

here admobobject.h

    #import "admobobject.h"     #import "rootviewcontroller.h"     #import "gadbannerview.h"      @class rootviewcontroller;     @class gadbannerview;     @interface admobobject : uiviewcontroller{         rootviewcontroller * viewcontroller;         gadbannerview * bannerview_;      }     + (admobobject *) shared;     - (void) addadmob;     - ( void) hideadmob;     @end 

here admobobject.mm

    #import "admobobject.h"     #import "appcontroller.h"     #import "rootviewcontroller.h"     #import "eaglview.h"     #import "cocos2d.h"      @implementation admobobject     static admobobject* instance;      +(admobobject *) shared{         @synchronized(self){             if( instance == nil ){                 instance = [[self alloc] init];             }         }         return instance;     }      - (void) addadmob{         nslog(@"----------addadmob");          bannerview_ = [[gadbannerview alloc] initwithadsize:kgadadsizesmartbannerportrait];         cgrect screenrect = [[uiscreen mainscreen] bounds];          cgfloat screenheight = screenrect.size.height;         cgfloat screenwidth = screenrect.size.width;          viewcontroller.view.frame = cgrectmake(0,0,screenwidth,screenheight);          [bannerview_ setframe:cgrectmake(0,                                           screenheight-bannerview_.bounds.size.height,                                          //0,                                          bannerview_.bounds.size.width,                                          bannerview_.bounds.size.height)];         bannerview_.adunitid = @"myadmobid";          bannerview_.rootviewcontroller = viewcontroller;         [viewcontroller.view addsubview:bannerview_];         gadrequest *request = [gadrequest request];         // testing         request.testdevices = [nsarray arraywithobjects:@"mydeviceid", nil];         [bannerview_ loadrequest:request];         [viewcontroller.view addsubview:bannerview_];      }     - (void) showadmob{      }     - (void) hideadmob{             [bannerview_ sethidden:yes];     }     @end 

then have class manage it:

@interface mygamecentermanager : nsobject {   } +(mygamecentermanager *) shared; +(void) addadmob; +(void) hideadmob;   @end 

here class implementation:

            @implementation mygamecentermanager      static mygamecentermanager *instance;       +(mygamecentermanager*)shared{          @synchronized(self){              if(instance == nil){                  instance = [[self alloc] init];              }         }          return instance;      }     + (void) addadmob     {          [[admobobject shared] addadmob];      }      + (void) hideadmob{          [[admobobject shared] hideadmob];     } 

finally, have cpp class:

include "cocos2d.h"

    #include "scriptingcore.h"     namespace ls{         class gamecenterbridge: public cocos2d::ccobject{          public:              static cocos2d::ccscene* scene();             virtual bool init();              create_func(gamecenterbridge);              void addadmob();             void hideadmob();          };      } 

i called class:

ls::gamecenterbridge * class = new ls::gamecenterbridge(); class->addadmob();

i can see console log:

----------addadmob

which means enter addadmob function. , there has no other errors.

but banner view didn't show.

the way make show add codes appcontroller.mm in didfinishlaunchingwithoptions. wondering why won't work self created class.

when implementing admob showed ad when got loaded server. can achieve implementing gadbannerviewdelegate, interesting methods

  1. - (void)adviewdidreceivead:(gadbannerview *)bannerview;
  2. - (void)adview:(gadbannerview *)bannerview didfailtoreceiveadwitherror:(gadrequesterror *)error

this way can sure received ad.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -