Created
November 18, 2019 12:46
-
-
Save dbrova15/d377d42075d8ec99dbf7fd95432cab00 to your computer and use it in GitHub Desktop.
Snippet to add to main.m in kivy-ios project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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