Examples
Set up a banner ad using the ‘adLoaded’ callback
This example demonstrates how to set up a banner ad with the Bumper page enabled, and display the ad as soon as it loads.
import SuperAwesome
class MyViewController: UIViewController {
var bannerAd: BannerView!
override func viewDidLoad() {
super.viewDidLoad()
bannerAd = BannerView()
// set up the Bumper page on the banner ad (optional)
bannerAd.enableBumperPage()
// add a callback
bannerAd.setCallback { [weak self] placementId, event in
// when the ad loads, play it directly
if event == .adLoaded {
self?.bannerAd.play()
}
}
// start the loading process
bannerAd.load(30471)
}
}
@import SuperAwesome;
@interface MyViewController: UIViewController
@property (weak, nonatomic) IBOutlet SABannerAd *bannerAd;
@end
@implementation MyViewController
- (void) viewDidLoad {
[super viewDidLoad];
// set up the Bumper page on the banner ad (optional)
[_bannerAd enableBumperPage];
// add a callback
__weak MyViewController *weakSelf = self;
[_bannerAd setCallback:^(NSInteger placementId, SAEvent event) {
// when the ad loads, play it directly
if (event == SAEventAdLoaded) {
[weakSelf.bannerAd play];
}
}];
// start the loading process
[_bannerAd load:30471];
}
@end
Set up multiple ads using the ‘HasAdAvailable’ method
This example demonstrates how to set up and display:
- a banner ad with the Parental Gate enabled.
- multiple video ads with the Bumper page enabled.
import SuperAwesome
class MyViewController: UIViewController {
var bannerAd: BannerView!
override func viewDidLoad() {
super.viewDidLoad()
bannerAd = BannerView()
// set up the Parental Gate on the banner ad (optional)
bannerAd.enableParentalGate()
// load the banner ad
bannerAd.load(30471)
// display the Bumper page on the video ad
VideoAd.enableBumperPage()
// disable the close button so the use has to watch the video
// through to the end
VideoAd.disableCloseButton()
// load the video ad
VideoAd.load(30479)
VideoAd.load(30480)
}
func playBanner() {
if bannerAd.hasAdAvailable() {
bannerAd.play()
}
}
func playVideo1() {
if VideoAd.hasAdAvailable(placementId: 30479) {
// set the orientation in which the video will play
VideoAd.setOrientationLandscape()
// and play the video
VideoAd.play(withPlacementId: 30479, fromVc: self)
}
}
func playVideo2() {
if VideoAd.hasAdAvailable(placementId: 30480) {
// set the orientation in which the video will play
VideoAd.setOrientationAny()
// and play the video
VideoAd.play(withPlacementId: 30480, fromVc: self)
}
}
}
@import SuperAwesome;
@interface MyViewController: UIViewController
@property (weak, nonatomic) IBOutlet SABannerAd *bannerAd;
@end
@implementation MyViewController
- (void) viewDidLoad {
[super viewDidLoad];
// set up the Parental Gate on the banner ad (optional)
[_bannerAd enableParentalGate];
// load the banner ad
[_bannerAd load:30471];
// display the Bumper page on the video ad
[SAVideoAd enableBumperPage];
// disable the close button so the use has to watch the video
// through to the end
[SAVideoAd disableCloseButton];
// load the video ad
[SAVideoAd load:30479];
[SAVideoAd load:30480];
}
- (IBAction) playBanner {
if ([_bannerAd hasAdAvailable]) {
[_bannerAd play];
}
}
- (IBAction) playVideo1 {
if ([SAVideoAd hasAdAvailable: 30479]) {
// set the orientation in which the video will play
[SAVideoAd setOrientationLandscape];
// and play the video
[SAVideoAd play: 30479 fromVC: self];
}
}
- (IBAction) playVideo2 {
if ([SAVideoAd hasAdAvailable: 30480]) {
// set the orientation in which the video will play
[SAVideoAd setOrientationAny];
// and play the video
[SAVideoAd play: 30480 fromVC: self];
}
}
@end