Skip to content

Instantly share code, notes, and snippets.

@thomasmso
Last active September 7, 2017 13:49
Show Gist options
  • Save thomasmso/59a3d258fe9dd164d8fe8c84fa12778f to your computer and use it in GitHub Desktop.
Save thomasmso/59a3d258fe9dd164d8fe8c84fa12778f to your computer and use it in GitHub Desktop.
Manual loading and programmatic SDK key example
@interface ALDemoViewController ()<ALAdLoadDelegate>
@property (nonatomic, strong) ALInterstitialAd *interstitial;
@property (nonatomic, strong) ALSdk *sdk;
@property (nonatomic, strong) ALAd *loadedAd;
@end
@implementation ALDemoViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.sdk = [ALSdk sharedWithKey: @"SDK_KEY"];
self.interstitial = [[ALInterstitialAd alloc] initWithSdk: self.sdk];
// Optional: Assign delegates
self.interstitial.adLoadDelegate = self;
self.interstitial.adDisplayDelegate = self;
self.interstitial.adVideoPlaybackDelegate = self;
}
- (IBAction)loadNextAd:(id)sender
{
[self.sdk.adService loadNextAd: [ALAdSize sizeInterstitial] andNotify: self];
}
- (IBAction)showInterstitial:(id)sender
{
if ( self.loadedAd )
{
[self.interstitial showOver: [UIApplication sharedApplication].keyWindow andRender: self.loadedAd];
self.loadedAd = nil;
}
}
#pragma mark - Ad Load Delegate
- (void)adService:(ALAdService *)adService didLoadAd:(ALAd *)ad
{
self.loadedAd = ad;
}
- (void) adService:(ALAdService *)adService didFailToLoadAdWithError:(int)code
{
// Look at ALErrorCodes.h for list of error codes
[self log: @"Interstitial failed to load with error code = %d", code];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment