Skip to content

Instantly share code, notes, and snippets.

@dbrova15
Created November 18, 2019 12:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbrova15/d377d42075d8ec99dbf7fd95432cab00 to your computer and use it in GitHub Desktop.
Save dbrova15/d377d42075d8ec99dbf7fd95432cab00 to your computer and use it in GitHub Desktop.
Snippet to add to main.m in kivy-ios project
UIView *gView;
UIViewController *gViewColtroller;
@interface adInterstitial : NSObject
/// The interstitial ad.
@property(nonatomic, strong) GADInterstitial *interstitial;
@property (strong, nonatomic) GADRequest *request;
@end
@implementation adInterstitial
-(id)init {
[self createAndLoadInterstitial];
NSLog(@"adInterstitial init");
return self;
}
- (void)createAndLoadInterstitial {
self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:@"ca-app-pub-3940256099942544/4411468910"]; // test id
UIWindow *window = [UIApplication sharedApplication].keyWindow;
UIViewController *rootViewController = window.rootViewController;
self.interstitial.delegate = self;
GADRequest *request = [GADRequest request];
request.testDevices = @[ kGADSimulatorID, @"2077ef9a63d2b398840261c8221a0c9a" ];
[self.interstitial loadRequest:request];
NSLog(@"createAndLoadInterstitial");
}
- (void)interstitialWillDismissScreen:(GADInterstitial *)ad {
// Method for reloading the object so that you can show ads again
NSLog(@"interstitialWillDismissScreen");
[self createAndLoadInterstitial];
}
- (void)InterstitialView { // show interstitial ADS
if (self.interstitial.isReady) {
NSLog(@"Show interstitial ADS!");
UIWindow *window = [UIApplication sharedApplication].keyWindow;
UIViewController *rootViewController = window.rootViewController;
[self.interstitial presentFromRootViewController:rootViewController];
} else {
NSLog(@"interstitial Ad wasn't ready");
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment