如何添加AdMob广告到现有的Unity3D ios游戏

如何添加AdMob广告到现有的Unity3D ios游戏,第1张

1.首先需要一个mac计算机安装unity(如果你本身就是用mac开发就跳过打包package的步骤) 2.将你要导出的项目打包成package到该计算机之后,选择IOS发布环境并bulid 3.bulid完成后会生成一个Xcode文件,用Xcode将其打开并配置好相关的信息(如版本。

1. 在.h中 声明变量 GADBannerView *adBanner_

2. 导入框架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. 如果有必要实现起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.

大功告成,运行程序就可以在屏幕上方看到admob广告了


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/7850452.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-10
下一篇2023-04-10

发表评论

登录后才能评论

评论列表(0条)

    保存