将广告添加到本机脚本

时间:2019-05-21 20:55:40

标签: admob nativescript

我想在我的应用程序中设置广告。我下载了admob库:https://www.npmjs.com/package/nativescript-admob。 什么都没有,给出此错误。告诉我出了什么事?还是还有其他图书馆?

错误:admob createBanner错误:TypeError:com.google.android.gms.ads.AdView不是构造函数

看到了这些问题的许多解决方案,但是什么也没发生

向manifest.xml添加标签没有返回任何结果。

home-page.js


import { EventData } from 'tns-core-modules/data/observable';
import { Page } from 'tns-core-modules/ui/page';
import { HomeViewModel } from './home-view-model';
var admobModule = require("../nativescript-admob");
// Event handler for Page "pageLoaded" event attached in home-page.xml
export function pageLoaded(args: EventData) {
    /*
    This gets a reference this page’s <Page> UI component. You can
    view the API reference of the Page to see what’s available at
    https://docs.nativescript.org/api-reference/classes/_ui_page_.page.html
    */
    let page = <Page>args.object;
    page.bindingContext = new HomeViewModel();
}



exports.createBanner = function () {
    admobModule.createBanner({
        testing: true,
        size: admobModule.AD_SIZE.SMART_BANNER,
        iosBannerId: "ca-app-pub-XXXX/YYYY",
        androidBannerId: "ca-app-pub-RRRR/TTTT",
        iosTestDeviceIds: ["yourTestDeviceUDIDs"],
        margins: {
            bottom: 0
        }
    }).then(function () {
        console.log("admob createBanner done");
    }, function (error) {
        console.log("admob createBanner error: " + error);
    });
}

exports.hideBanner = function () {
    admobModule.hideBanner().then(function () {
        console.log("admob hideBanner done");
    }, function (error) {
        console.log("admob hideBanner error: " + error);
    });
}

exports.createInterstitial = function () {
    admobModule.createInterstitial({
        testing: true,
        iosInterstitialId: "ca-app-pub-KKKK/LLLL",
        androidInterstitialId: "ca-app-pub-GGGG/HHHH",
        iosTestDeviceIds: ["yourTestDeviceUDIDs"]
    }).then(function () {
        console.log("admob createInterstitial done");
    }, function (error) {
        console.log("admob createInterstitial error: " + error);
    });
}

home-page.xml


<Page loaded="pageLoaded" class="page" navigatingTo="onNavigatingTo" xmlns="http://www.nativescript.org/tns.xsd">
    <ActionBar title="Home" class="action-bar">
    </ActionBar>

    <StackLayout>
        <Button text="Create Banner" tap="createBanner" />
        <Button text="Hide Banner" tap="hideBanner" />
        <Button text="Create Interstitial" tap="createInterstitial" />
    </StackLayout>
</Page>

0 个答案:

没有答案