很少說,看步驟。測試
下載admob廣告sdk.ui
把SDK中的以下文件,除了那個文件夾,所有拖到工程裏。google
導入文件(googleAD是個人上級文件夾名)#import "googleAD/GADBannerView.h"spa
加入私有屬性@property(nonatmic,strong)GADBannerView *ADBanner;code
;orm
-(void)addAD { //我是頂部廣告,頂部還有導航(push) float y=self.navigationController.navigationBar.frame.size.height+[[UIApplication sharedApplication] statusBarFrame].size.height; float x=([UIScreen mainScreen].bounds.size.width-320)/2; self.ADBanner=[[GADBannerView alloc]initWithAdSize:kGADAdSizeBanner origin:CGPointMake(x, y)]; self.ADBanner.adUnitID=MY_BANNER_ID; self.ADBanner.rootViewController=self; [self.view addSubview:self.ADBanner]; GADRequest *request=[GADRequest request]; request.testDevices=@[GAD_SIMULATOR_ID,MY_DEVICE_ADID]; [self.ADBanner loadRequest:request]; }
6.it
#define MY_BANNER_ID @"6666666666666你得廣告id"io
#define MY_DEVICE_ADID @"你得測試id"class
7.test
工程設置
選擇藍色頂級項目圖標》點擊build setting>Other Linker Flags 下添加-ObjC
還要添加:-all_load
ok.