原生脚本货币化和广告,AdMob 插件



我想创建一个带有nativescript的付费应用程序并将其保存在"Play商店"中。但我想允许下载我的应用程序作为"免费广告"。我应该使用哪个选项?如果我选择付费版本,则无法下载,所以我应该选择"在应用程序中付款"吗?

https://play.google.com/about/monetization-ads/payments/

我打算使用 NativeScript AdMob 插件来管理广告,但我怎么知道该用户已经付款,我不应该为他初始化我的广告?

https://plugins.nativescript.rocks/plugin/nativescript-admob

假设您nativescript-admob插件与nativescript-purchase一起使用。然后,您可以跟踪何时购买恢复产品,并通过application-settings模块"记住"这一点。

例如

import {getBoolean, setBoolean } from "tns-core-modules/application-settings";
// ... more code follow here
if (transaction.transactionState === TransactionState.Purchased) {
/* Purchase of the FULL  version */
if (transaction.productIdentifier.indexOf(".full") >= 0) {
setBoolean(transaction.productIdentifier, true);
}
// ... more code follows here

然后,在打开 AdMob 广告之前,请检查产品是否通过getBoolean进行宣传。

例如:

this.isPurchased = getBoolean(fullVersionPurchase); // fullVersionPurchase === transaction.productIdentifie
if (!this.isPurchased) {
this.showBanner(); // where showBaneer is your AdMob functionality
}

按照相同的逻辑,您可以在成功购买(或恢复(后立即直接关闭横幅。

if (transaction.transactionState === TransactionState.Purchased) {
if (transaction.productIdentifier.indexOf(".full") >= 0) {
setBoolean(transaction.productIdentifier, true);
}
try {
admob.hideBanner();
} catch (err) { }

通过上述方法,您可以创建一个 AdMob 附带的免费应用,然后在用户购买完整版时立即提供完整版功能。有关nativescript-purchase功能的更多详细信息,请参阅此处。

最新更新