怎樣設(shè)置admob的廣告 ios?
我來(lái)答

怎樣設(shè)置admob的廣告 ios?

小尤 2020-07-22 提問(wèn)
221

如題,請(qǐng)教一下怎么才能設(shè)置Google Admob的廣告?

關(guān)閉
提交回答
1 個(gè)回答
我來(lái)答
佘軍

1. 在.h中聲明變量 GADBannerView *adBanner_;

2. 導(dǎo)入框架MessageUK.framework, AudioToolbox.framework, systemConfiguration.framework

3. 在viewDidAppear(或者其他地方)加入如下代碼:

 CGPoint origin = CGPointMake(0.0, 0.0);

 // Use predefined GADAdSize constants to define the GADBannerView.

 self.adBanner = [[[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner

 origin:origin] autorelease];

 // Note: Edit SampleConstants.h to provide a definition for kSampleAdUnitID

 // before compiling.

 self.adBanner.adUnitID = kSampleAdUnitID;

 self.adBanner.delegate = self;

 [self.adBanner setRootViewController:self];

 [self.view addSubview:self.adBanner];

 [self.adBanner loadRequest: [GADRequest request]];

4. 如果有必要實(shí)現(xiàn)起delegate方法

 #pragma mark GADBannerViewDelegate impl

 // We've received an ad successfully.

 - (void)adViewDidReceiveAd:(GADBannerView *)adView {

 NSLog(@"Received ad successfully");

 }

 - (void)adView:(GADBannerView *)view

 didFailToReceiveAdWithError:(GADRequestError *)error {

 NSLog(@"Failed to receive ad with error: %@", [error localizedFailureReason]);

 }

5. 在build Setting中,將 Other Linker Flags, add -ObjC to both Debug and Release.

大功告成,運(yùn)行程序就可以在屏幕上方看到admob廣告了

回答于 2020-07-22
贊同
評(píng)論
掃碼關(guān)注
獲取更多出海問(wèn)答的相關(guān)信息
小程序
快出海小程序
公眾號(hào)
快出海公眾號(hào)
商務(wù)合作
商務(wù)合作
投稿采訪
投稿采訪
出海管家
出海管家