ejanowski
ejanowski

Reputation: 538

Interstitial implementation

For the most of the apps of my company, we display interstitials. First we load it, and when it load, we display it.

Sometimes (rarely) the interstitial is present while a transition is in progress (pushviewcontroller for example).

I was wondering if it is a good solution to present the interstitial in another window of the hierarchy viewcontrollers.

Do something like that :

- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
    mWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    UIViewController* controller = [[UIViewController alloc] init];
    controller.view.backgroundColor = [UIColor clearColor];
    mWindow.backgroundColor = [UIColor clearColor];
    mWindow.rootViewController = controller;
    [mWindow makeKeyAndVisible];
    [self.interstitial presentFromRootViewController:mWindow.rootViewController];
}

- (void) interstitialDidDismissScreen:(GADInterstitial *)ad {
    [mWindow removeFromSuperview];
    mWindow = nil;
}

Is that ugly ?

Upvotes: 0

Views: 140

Answers (1)

RayChen
RayChen

Reputation: 1468

I don't think it is a good practise to present the interstitial in another window of the hierarchy viewcontrollers, and we can't say it's wrong. From apple document,

The UIWindow class defines an object known as a window that manages and >coordinates the views an app displays on a device screen. Unless an app can display content on an external device screen, an app has only one window. https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIWindow_Class/

Upvotes: 1

Related Questions