jay
jay

Reputation: 3667

Crash while presenting a view controller after closing Google Mobile Ads Splash Interstitial

iOS App is crashing, if we try to present a view after dismissing the Google Mobile Ads Splash Interstitial.

Simulator Version : iOS 7.1(4 inch 64 bit) Google Mobile Ads SDK Version : 6.9.2

Code for presenting splash ad(application:didFinishLaunchingWithOptions:) :

InitialSlidingViewController *controller = [[InitialSlidingViewController alloc] init];
[self.window setRootViewController:controller];

splashInterstitial_ = [[DFPInterstitial alloc] init];
splashInterstitial_.adUnitID = SplashInterstitialID;
GADRequest *request = [GADRequest request];
splashInterstitial_.delegate = self;
request.testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];
[splashInterstitial_ loadAndDisplayRequest:request
                               usingWindow:window_
                              initialImage:[UIImage imageNamed:imageName]];

[self.window setBackgroundColor:[UIColor blackColor]];
[self.window makeKeyAndVisible];

Delegate Methods used

    - (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 used for presenting view

NewViewController *newVC = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
    UINavigationController *nav = [[PortraitNavController alloc] initWithRootViewController:newVC];
    nav.navigationBarHidden = YES;
    [self.navigationController presentViewController:nav animated:YES completion:nil];

//Crash Log from console:

* -[GADWebAppViewController isKindOfClass:]: message sent to deallocated instance 0x573efe90

Upvotes: 2

Views: 1577

Answers (1)

jay
jay

Reputation: 3667

Solved this issue by moving the code for presenting interstitial to Rootviewcontroller. This solution is recommended in Google Ads Developer official blog.

//MyRootViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];

    // Remember whether the status bar was hidden or not.
    hideStatusBar_ = [UIApplication sharedApplication].statusBarHidden;

    splashInterstitial_ = [[DFPInterstitial alloc] init];
    splashInterstitial_.adUnitID = SplashInterstitialID;
    splashInterstitial_.delegate = self;

    GADRequest *request = [GADRequest request];
    request.testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];
    [splashInterstitial_ loadRequest:request];
}

#pragma mark - splashInterstitial delegate methods

- (void)restoreController {
    if (imageView_ != nil) {
        [imageView_ removeFromSuperview];
    }
    [UIApplication sharedApplication].statusBarHidden = hideStatusBar_;
}

- (void)interstitialDidReceiveAd:(GADInterstitial *)ad {

    [splashInterstitial_ presentFromRootViewController:self];
}

- (void)interstitial:(DFPInterstitial *)interstitial didFailToReceiveAdWithError:(GADRequestError *)error {

    [self restoreController];
}

- (void)interstitialWillDismissScreen:(GADInterstitial *)ad {
    [self restoreController];
}

- (void)interstitialDidDismissScreen:(GADInterstitial *)ad {
    //Dismiss Delegate
}

imageView_ is a full screen image view contains the same splash screen image.

Upvotes: 2

Related Questions