|
3 | 3 | <img src="images/features/admob.png" width="296px" height="124px" alt="admob"/> |
4 | 4 |
|
5 | 5 | ## Enabling AdMob |
6 | | -Since plugin version 3... you can use Firebase _AdMob_ features. |
| 6 | +Since plugin version 3.10.0 you can use Firebase _AdMob_ features. |
7 | 7 |
|
8 | | -_AdMob_ lets you .. |
| 8 | +_AdMob_ lets you show banners or interstitials (full screen ads) in your app so you can earn a little money. |
9 | 9 |
|
10 | | -WORK IN PROGRESS.. updating right now (Feb 17, 2017) |
| 10 | +### iOS |
| 11 | + |
| 12 | +#### App Transport Security |
| 13 | +Open `app/App_Resources/iOS/Info.plist` and add this to the bottom: |
| 14 | + |
| 15 | +```xml |
| 16 | +<key>NSAppTransportSecurity</key> |
| 17 | +<dict> |
| 18 | + <key>NSAllowsArbitraryLoads</key> |
| 19 | + <true/> |
| 20 | + <key>NSAllowsArbitraryLoadsForMedia</key> |
| 21 | + <true/> |
| 22 | + <key>NSAllowsArbitraryLoadsInWebContent</key> |
| 23 | + <true/> |
| 24 | +</dict> |
| 25 | +``` |
| 26 | + |
| 27 | +[More info on this subject.](https://firebase.google.com/docs/admob/ios/app-transport-security) |
| 28 | + |
| 29 | +## Functions |
| 30 | + |
| 31 | +### admob.showBanner |
| 32 | +Go [manage your AdMob app](https://apps.admob.com/#account/appmgmt:) and grab the banner, then show it in your app: |
| 33 | + |
| 34 | +```js |
| 35 | + firebase.admob.showBanner({ |
| 36 | + size: firebase.admob.AD_SIZE.SMART_BANNER, // see firebase.admob.AD_SIZE for all options |
| 37 | + margins: { // optional nr of device independent pixels from the top or bottom (don't set both) |
| 38 | + bottom: 10, |
| 39 | + top: 0 |
| 40 | + }, |
| 41 | + androidBannerId: "ca-app-pub-9517346003011652/7749101329", |
| 42 | + iosBannerId: "ca-app-pub-9517346003011652/3985369721", |
| 43 | + testing: true, // when not running in production set this to true, Google doesn't like it any other way |
| 44 | + iosTestDeviceIds: [ //Android automatically adds the connected device as test device with testing:true, iOS does not |
| 45 | + "45d77bf513dfabc2949ba053da83c0c7b7e87715", // Eddy's iPhone 6s |
| 46 | + "fee4cf319a242eab4701543e4c16db89c722731f" // Eddy's iPad Pro |
| 47 | + ] |
| 48 | + }).then( |
| 49 | + function () { |
| 50 | + console.log("AdMob banner showing"); |
| 51 | + }, |
| 52 | + function (errorMessage) { |
| 53 | + dialogs.alert({ |
| 54 | + title: "AdMob error", |
| 55 | + message: errorMessage, |
| 56 | + okButtonText: "Hmmkay" |
| 57 | + }); |
| 58 | + } |
| 59 | + ); |
| 60 | +``` |
| 61 | + |
| 62 | +### admob.hideBanner |
| 63 | +Easy peasy: |
| 64 | + |
| 65 | +```js |
| 66 | + firebase.admob.hideBanner().then( |
| 67 | + function () { |
| 68 | + console.log("AdMob banner hidden"); |
| 69 | + }, |
| 70 | + function (errorMessage) { |
| 71 | + dialogs.alert({ |
| 72 | + title: "AdMob error", |
| 73 | + message: errorMessage, |
| 74 | + okButtonText: "Hmmkay" |
| 75 | + }); |
| 76 | + } |
| 77 | + ); |
| 78 | +``` |
| 79 | + |
| 80 | +### admob.showInterstitial |
| 81 | +This is a fullscreen ad, so you can earn extra credit on the eternal ladder of annoyance. |
| 82 | + |
| 83 | +Note that an interstitial is supposed to be hidden by clicking the close button, so there's no function to do it programmatically. |
| 84 | + |
| 85 | +```js |
| 86 | + firebase.admob.showInterstitial({ |
| 87 | + iosInterstitialId: "ca-app-pub-9517346003011652/6938836122", |
| 88 | + androidInterstitialId: "ca-app-pub-9517346003011652/6938836122", |
| 89 | + testing: true, // when not running in production set this to true, Google doesn't like it any other way |
| 90 | + iosTestDeviceIds: [ // Android automatically adds the connected device as test device with testing:true, iOS does not |
| 91 | + "45d77bf513dfabc2949ba053da83c0c7b7e87715", // Eddy's iPhone 6s |
| 92 | + "fee4cf319a242eab4701543e4c16db89c722731f" // Eddy's iPad Pro |
| 93 | + ] |
| 94 | + }).then( |
| 95 | + function () { |
| 96 | + console.log("AdMob interstitial showing"); |
| 97 | + }, |
| 98 | + function (errorMessage) { |
| 99 | + dialogs.alert({ |
| 100 | + title: "AdMob error", |
| 101 | + message: errorMessage, |
| 102 | + okButtonText: "Hmmkay" |
| 103 | + }); |
| 104 | + } |
| 105 | + ); |
| 106 | +``` |
| 107 | + |
| 108 | +## What about the nativescript-admob plugin? |
| 109 | +There's currently no functional difference between the AdMob features in the Firebase plugin and |
| 110 | +[nativescript-admob](https://github.com/EddyVerbruggen/nativescript-admob). |
| 111 | + |
| 112 | +The main advantage of using the version in the Firebase plugin is to avoid a gradle build conflict |
| 113 | +in the Android build you may encounter when including both plugins in your app. |
0 commit comments