Git Product home page Git Product logo

nativescript-admob's Introduction

NativeScript AdMob plugin

Earn some well earned $$$ with your {N} app by adding Google AdMob banners.

Installation

From the command prompt go to your app's root folder and execute:

tns plugin add nativescript-admob

Usage

If you want a quickstart, clone our demo app.

Here are the supported functions:

createBanner

  var admob = require("nativescript-admob");

  admob.createBanner({
      // if this 'view' property is not set, the banner is overlayed on the current top most view
      // view: ..,
      testing: true, // set to false to get real banners
      size: size, // anything in admob.AD_SIZE, like admob.AD_SIZE.SMART_BANNER
      iosBannerId: "ca-app-pub-XXXXXX/YYYYYY", // add your own
      androidBannerId: "ca-app-pub-AAAAAAAA/BBBBBBB", // add your own
      // Android automatically adds the connected device as test device with testing:true, iOS does not
      iosTestDeviceIds: ["yourTestDeviceUDIDs", "canBeAddedHere"],
      margins: {
        // if both are set, top wins
        //top: 10
        bottom: 50
      }
    }).then(
        function() {
          console.log("admob createBanner done");
        },
        function(error) {
          console.log("admob createBanner error: " + error);
        }
  )

Note that you can trigger the function above at any moment, and since version 1.1.4 of this plugin you can even call it from the Page.loaded event.

hideBanner

NOTE: If you want to show a different banner than the one showing you don't need to call hideBanner since createBanner will do that for you to prevent your app from crashing.

  // the .then(.. bit is optional btw
  admob.hideBanner().then(
        function() {
          console.log("admob hideBanner done");
        },
        function(error) {
          console.log("admob hideBanner error: " + error);
        }
  )

createInterstitial

To show a fullscreen banner you can use this function. Note that Interstitial banners need to be loaded before they can be shown, but don't worry: this plugin will manage that transparently for you.

  admob.createInterstitial({
      testing: true,
      iosInterstitialId: "ca-app-pub-XXXXXX/YYYYY2", // add your own
      androidInterstitialId: "ca-app-pub-AAAAAAAA/BBBBBB2", // add your own
      // Android automatically adds the connected device as test device with testing:true, iOS does not
      iosTestDeviceIds: ["ce97330130c9047ce0d4430d37d713b2"]
    }).then(
        function() {
          console.log("admob createInterstitial done");
        },
        function(error) {
          console.log("admob createInterstitial error: " + error);
        }
  )

Tutorials

Need a little more help getting started? Check out these tutorials for using Admob in a NativeScript Android and iOS application.

nativescript-admob's People

Contributors

eddyverbruggen avatar nraboy avatar sis0k0 avatar

Watchers

James Cloos avatar MattWilliams avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.