I'm trying to get adverts working using this plugin in an Ionic app, and getting very inconsistent results with interstitials and banners.
The current code sets up the interstitial and banner in $ionicPlatform.ready():
angular.module('myApp',
[
'ionic',
'ngCordova',
'ngIOS9UIWebViewPatch'
])
.constant('myConf', {
ads: {
appBanner: '/1234567/*******************',
appInterstitial: '/1234567/*******************',
roaInterstitial: '/1234567/*******************'
}
})
.run(function ($ionicPlatform, $rootScope, $ionicLoading, myConf, $cordovaKeyboard, $cordovaGoogleAds) {
$ionicPlatform.ready(function () {
if ($cordovaKeyboard) {
$cordovaKeyboard.hideAccessoryBar(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
if (AdMob) {
AdMob.prepareInterstitial({
interstitialAdId: myConf.ads.roaInterstitial,
autoShow: false
});
AdMob.createBanner({
adId: myConf.ads.appBanner,
autoShow: false
});
}
});
)};
Then in main.js and in controllers:
if (AdMob) {
AdMob.showInterstitial();
}
and
if (AdMob) {
AdMob.showBanner(AdMob.AD_POSITION.BOTTOM_CENTER);
}
Admittedly the code is wrapped in callbacks and a little more complex, but in tests, I have paired the code down to this, taking the advert code out of the if statement or doing a console.log within the if statement (the code is definitely entering the if statement), and also tried autoShow: true, with the same results.
We are testing on ios & android simulator and ionic view. The advert codes are correct and there are no frequency or other limitations on these test adverts.
I am seeing the banner consistently on ios simulator, but not on android or ios devices (through ionic view).
The interstitial has only appeared very occasionally on ios simulator, and never on ios or android devices.
If I run:
$ ionic run ios -l -c
I see multiple warnings from cordova-plugin-extension:
while processing /Library/WebServer/www/my_app/platforms/ios/myApp/Plugins/cordova-plugin-extension/libCordovaGenericAd.a(GenericAdPlugin.o):
warning: /Users/liming/Library/Developer/Xcode/DerivedData/ModuleCache/1UIOVPNM0I1EA/CoreGraphics-N94D31PLFESQ.pcm: No object file for requested architecture
while processing /Library/WebServer/www/my_app/platforms/ios/myApp/Plugins/cordova-plugin-extension/libCordovaGenericAd.a(GenericAdPlugin.o):
warning: Could not resolve external type c:objc(cs)NSObject
I don't know if this is related, although I see that this is supposedly fixed in https://github.com/floatinghotpot/cordova-extension/issues/5
The final solution has been found - ionic view was blocking the adverts! As soon as I compiled the app and distributed it over itunes connect, they worked!
There was a couple of hurdles that I had to overcome to compiling, which I'll share so that anyone with similar issues can find the answer:
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ld: bitcode bundle could not be generated because '/Library/WebServer/www/myApp/platforms/ios/myApp/Plugins/cordova-plugin-extension/libCordovaGenericAd.a(GenericAdPlugin.o)' was built without full bitcode. All object files and libraries for bitcode must be generated from Xcode Archive or Install build for architecture armv7