Since plugin version 3.10.0 you can use Firebase AdMob features.
AdMob lets you show banners or interstitials (full screen ads) in your app so you can earn a little money.
Open app/App_Resources/iOS/Info.plist
and add this to the bottom:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsForMedia</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
</dict>
Go manage your AdMob app and grab the banner, then show it in your app:
firebase.admob.showBanner({
size: firebase.admob.AD_SIZE.SMART_BANNER, // see firebase.admob.AD_SIZE for all options
margins: { // optional nr of device independent pixels from the top or bottom (don't set both)
bottom: 10,
top: 0
},
androidBannerId: "ca-app-pub-9517346003011652/7749101329",
iosBannerId: "ca-app-pub-9517346003011652/3985369721",
testing: true, // when not running in production set this to true, Google doesn't like it any other way
iosTestDeviceIds: [ //Android automatically adds the connected device as test device with testing:true, iOS does not
"45d77bf513dfabc2949ba053da83c0c7b7e87715", // Eddy's iPhone 6s
"fee4cf319a242eab4701543e4c16db89c722731f" // Eddy's iPad Pro
]
}).then(
function () {
console.log("AdMob banner showing");
},
function (errorMessage) {
dialogs.alert({
title: "AdMob error",
message: errorMessage,
okButtonText: "Hmmkay"
});
}
);
Easy peasy:
firebase.admob.hideBanner().then(
function () {
console.log("AdMob banner hidden");
},
function (errorMessage) {
dialogs.alert({
title: "AdMob error",
message: errorMessage,
okButtonText: "Hmmkay"
});
}
);
This is a fullscreen ad, so you can earn extra credit on the eternal ladder of annoyance.
Note that an interstitial is supposed to be hidden by clicking the close button, so there's no function to do it programmatically.
firebase.admob.showInterstitial({
iosInterstitialId: "ca-app-pub-9517346003011652/6938836122",
androidInterstitialId: "ca-app-pub-9517346003011652/6938836122",
testing: true, // when not running in production set this to true, Google doesn't like it any other way
iosTestDeviceIds: [ // Android automatically adds the connected device as test device with testing:true, iOS does not
"45d77bf513dfabc2949ba053da83c0c7b7e87715", // Eddy's iPhone 6s
"fee4cf319a242eab4701543e4c16db89c722731f" // Eddy's iPad Pro
]
}).then(
function () {
console.log("AdMob interstitial showing");
},
function (errorMessage) {
dialogs.alert({
title: "AdMob error",
message: errorMessage,
okButtonText: "Hmmkay"
});
}
);
There's currently no functional difference between the AdMob features in the Firebase plugin and nativescript-admob.
The main advantage of using the version in the Firebase plugin is to avoid a gradle build conflict in the Android build you may encounter when including both plugins in your app.