0
控制檯中沒有錯誤,看起來一切正常。但bannerView_只是沒有顯示。爲什麼我的admob不顯示?
這裏是我的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
這裏是我的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];
// For testing
request.testDevices = [NSArray arrayWithObjects:@"mydeviceid", nil];
[bannerView_ loadRequest:request];
[viewController.view addSubview:bannerView_];
}
- (void) showAdMob{
}
- (void) hideAdMob{
[bannerView_ setHidden:YES];
}
@end
然後,我有一個類來管理它:
@interface MyGameCenterManager : NSObject
{
}
+(MyGameCenterManager *) shared;
+(void) addAdMob;
+(void) hideAdMob;
@end
這裏是類執行:
@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];
}
最後,我有CPP類:
包括 「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();
};
}
我叫我的課:
LS :: GameCenterBridge *類=新款LS :: GameCenterBridge( ); class-> addAdMob();
我可以看到控制檯日誌:
---------- addAdMob
這意味着它進入addAdMob功能。並沒有其他錯誤。
但橫幅視圖只是沒有顯示。
我使它顯示的唯一方法是將代碼添加到didFinishLaunchingWithOptions中的AppController.mm中。但我只是想知道爲什麼它不適合我自己創建的課程。