Vote count:
0
I am trying to implement Admob Interstitial ads on ios.
Here is what I have so far, this is my first time ever touching objective-c so please be kind.
// Simple Admob Interstitial support for Monkey - IOS
// admobInterstitial.ios.h
#import "GADInterstitial.h"
class AdmobInterstitial {
// the kind of "singleton"
static AdmobInterstitial *_admob;
// the ad
GADInterstitial *_interstitialAd;
// ad Unit ID
NSString *adUnitId;
public:
AdmobInterstitial();
// creates an instance of the object and start the thread
static AdmobInterstitial *GetAdmobInterstitial(String adUnitId);
// displays the ad to the user if it is ready
void ShowAd();
};
// admobInterstitial.ios.cpp
AdmobInterstitial *AdmobInterstitial::_admob;
AdmobInterstitial::AdmobInterstitial():_interstitialAd(0) {
}
AdmobInterstitial *AdmobInterstitial::GetAdmobInterstitial(String adUnitId) {
if( !_admob ) _admob=new AdmobInterstitial();
_admob->adUnitId = adUnitId.ToNSString();
return _admob;
}
void AdmobInterstitial::ShowAd() {
// create ad (should this go here or earlier?)
_interstitialAd = [[GADInterstitial alloc] init];
if (_interstitialAd) {
_interstitialAd.adUnitID = adUnitId;
[_interstitialAd loadRequest:[GADRequest request]];
if (_interstitialAd.isReady) {
BBMonkeyAppDelegate *appDelegate=(BBMonkeyAppDelegate*)[[UIApplication sharedApplication] delegate];
UIViewController *rootViewController = appDelegate->viewController;
[_interstitialAd presentFromRootViewController:rootViewController];
}
}
}
I am calling ShowAd() in my game after a player dies and clicks the restart button. Currently, _interstitialAd.isReady is not coming back as true.
This is the documentation I used to get started http://ift.tt/1nIUDB3
It says that "You may invoke loadRequest: at any time, however, you must wait for GADInterstitialDelegate's interstitialDidReceiveAd: to be called before displaying the creative."
I assume this is the problem I am running into. I think I am calling loadRequest before interstitialDidReceiveAd. However, the document doesn't show an example of how I would wait for this method to be called.
Can anyone help with this?
Aucun commentaire:
Enregistrer un commentaire