ios - 关闭 Google Mobile Ads Splash Interstitial 后呈现 View Controller 时崩溃
<p><p>如果我们在关闭 Google 移动广告后尝试呈现 View ,iOS 应用会崩溃 <a href="https://developers.google.com/mobile-ads-sdk/docs/admob/advanced#splashinterstitials" rel="noreferrer noopener nofollow">Splash Interstitial</a> .</p>
<p>模拟器版本:iOS 7.1(4寸64位)
谷歌移动广告 SDK 版本:6.9.2</p>
<p>展示初始广告的代码(application:didFinishLaunchingWithOptions:) :</p>
<pre><code>InitialSlidingViewController *controller = [ init];
;
splashInterstitial_ = [ init];
splashInterstitial_.adUnitID = SplashInterstitialID;
GADRequest *request = ;
splashInterstitial_.delegate = self;
request.testDevices = ;
[splashInterstitial_ loadAndDisplayRequest:request
usingWindow:window_
initialImage:];
];
;
</code></pre>
<p>使用的委托(delegate)方法</p>
<pre><code> - (void)interstitial:(DFPInterstitial *)interstitial didFailToReceiveAdWithError:(GADRequestError *)error {
//present a view
}
- (void)interstitialDidDismissScreen:(GADInterstitial *)ad {
ad.delegate = nil;
splashInterstitial_.delegate = nil;
ad = nil;
splashInterstitial_ = nil;
//Present a view controller
}
</code></pre>
<p>用于呈现 View 的代码</p>
<pre><code>NewViewController *newVC = [ initWithNibName:@"NewViewController" bundle:nil];
UINavigationController *nav = [ initWithRootViewController:newVC];
nav.navigationBarHidden = YES;
;
</code></pre>
<p>//来自控制台的崩溃日志:</p>
<blockquote>
<p><em>*</em> -: message sent to deallocated instance 0x573efe90</p>
</blockquote></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>通过将用于呈现插页式广告的代码移至 <code>Rootviewcontroller</code> 解决了这个问题。 <a href="http://googleadsdeveloper.blogspot.in/2012/11/create-your-own-version-of.html" rel="noreferrer noopener nofollow">Google Ads Developer official blog</a> 中推荐此解决方案. </p>
<pre><code>//MyRootViewController.m
- (void)viewDidLoad {
;
// Remember whether the status bar was hidden or not.
hideStatusBar_ = .statusBarHidden;
splashInterstitial_ = [ init];
splashInterstitial_.adUnitID = SplashInterstitialID;
splashInterstitial_.delegate = self;
GADRequest *request = ;
request.testDevices = ;
;
}
#pragma mark - splashInterstitial delegate methods
- (void)restoreController {
if (imageView_ != nil) {
;
}
.statusBarHidden = hideStatusBar_;
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)ad {
;
}
- (void)interstitial:(DFPInterstitial *)interstitial didFailToReceiveAdWithError:(GADRequestError *)error {
;
}
- (void)interstitialWillDismissScreen:(GADInterstitial *)ad {
;
}
- (void)interstitialDidDismissScreen:(GADInterstitial *)ad {
//Dismiss Delegate
}
</code></pre>
<p><code>imageView_</code> 是一个全屏 ImageView ,包含相同的初始屏幕图像。 </p></p>
<p style="font-size: 20px;">关于ios - 关闭 Google Mobile Ads Splash Interstitial 后呈现 ViewController 时崩溃,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/23802031/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/23802031/
</a>
</p>
页:
[1]