Ads
The DarkMatter framework includes an Ads subsystem that is an easy to use library for displaying interstitial ads and rewarded video ads in a game. The library handles configuring and pre-loading ad networks automatically, all the developer has to do is choose when to show an interstitial or rewarded video.
Usage
Ad Network Configuration
Ad networks are configured in the morefunadapi key in a game’s manifest.
The preloadInterstitial and preloadRewardVideo keys were added in DarkMatter 4.1.0 and they allow you to enable or disable the pre-loading of ads. When disabled, ads will be loaded when the showAd method is called.
Note: If pre-loading is disabled the
isAdReadymethods will always returntrue.
Initialize Ads
If DarkMatter is integrated in your game all you need to do to be able to use the Ads subsytem is ensure the AdsNode is added to the requiredNodes array when initializing Hive.
// Swift
HiveManager.instance.requiredNodes = [MyAppDarkMatterNode.self,
MyAppGameServiceNode.self,
AdsNode.self]
// Objective-C
HiveManager.instance.requiredNodes = @[MyAppDarkMatterNode.class,
MyAppGameServiceNode.class,
AdsNode.class];
Set a Delegate
If you want to listen for callbacks related to ads you can optionally set a delegate that conforms to the AdsDelegate protocol.
// Swift
Ads.setDelegate(self)
// Objective-C
[Ads setDelegate:self];
Display an Ad
When you want to display an interstitial, simply make the call to show an ad with a placement tag string and the library will display an interstitial when one is ready. The placement tag is used to control the frequency of ad presented. You can check to see if an interstitial is ready to be shown, and if one is not ready yet you can continue on with your game as normal.
// Swift
if Ads.isAdReady() {
Ads.showAd("main_menu", on: self)
}
// Objective-C
if ([Ads isAdReady]) {
[Ads showAd:@"main_menu" onViewController:self];
}
When you want to trigger a rewarded video ad, make a similar call with a placement tag string. Again, check to see if a rewarded video is ready to be shown.
// Swift
if Ads.isRewardedVideoAdReady() {
Ads.showRewardedVideoAd("rewarded_video", on: self)
}
// Objective-C
if ([Ads isRewardedVideoAdReady]) {
[Ads showRewardedVideoAd:@"rewarded_video" onViewController:self];
}
Integrating Ads Reference