@nativescript/google-mobile-ads
Version:
NativeScript Google mobile Ads
75 lines • 3.31 kB
JavaScript
import { Application, Utils } from '@nativescript/core';
import { AdsConsentBase, AdsConsentDebugGeography, AdsConsentStatus } from './common';
import { MobileAdsError } from '../error';
export { AdsConsentStatus, AdsConsentDebugGeography };
export class AdsConsent extends AdsConsentBase {
static reset() {
org.nativescript.plugins.google_mobile_ads.GoogleMobileAds.AdConsent.reset(Utils.android.getApplicationContext());
}
static addTestDevices(deviceIds) {
this._deviceIds = deviceIds;
}
static getStatus() {
return org.nativescript.plugins.google_mobile_ads.GoogleMobileAds.AdConsent.getStatus(Utils.android.getApplicationContext());
}
static requestInfoUpdate() {
return new Promise((resolve, reject) => {
const info = {};
if (this._geography) {
info['geography'] = this._geography;
}
if (this._deviceIds) {
info['deviceIds'] = this._deviceIds;
}
if (typeof this._tagForUnderAgeOfConsent === 'boolean') {
info['tagForUnderAgeOfConsent'] = this._tagForUnderAgeOfConsent;
}
org.nativescript.plugins.google_mobile_ads.GoogleMobileAds.AdConsent.requestInfoUpdate(Application.android.foregroundActivity || Application.android.startActivity, JSON.stringify(info), new org.nativescript.plugins.google_mobile_ads.GoogleMobileAds.Callback({
onSuccess(value) {
resolve();
},
onError(error) {
reject(MobileAdsError.fromNative(error));
},
}));
});
}
static setDebugGeography(geography) {
this._geography = geography;
}
static setTagForUnderAgeOfConsent(tag) {
this._tagForUnderAgeOfConsent = tag;
}
static isConsentFormAvailable() {
if (!this._consentInfo) {
this._consentInfo = com.google.android.ump.UserMessagingPlatform.getConsentInformation(Utils.android.getApplicationContext());
}
return this._consentInfo.isConsentFormAvailable();
}
static showForm() {
return new Promise((resolve, reject) => {
org.nativescript.plugins.google_mobile_ads.GoogleMobileAds.AdConsent.show(Application.android.foregroundActivity || Application.android.startActivity, this._consentForm, new org.nativescript.plugins.google_mobile_ads.GoogleMobileAds.Callback({
onSuccess(val) {
resolve();
},
onError(error) {
reject(MobileAdsError.fromNative(error));
},
}));
});
}
static loadForm() {
return new Promise((resolve, reject) => {
org.nativescript.plugins.google_mobile_ads.GoogleMobileAds.AdConsent.load(Utils.android.getApplicationContext(), new org.nativescript.plugins.google_mobile_ads.GoogleMobileAds.Callback({
onSuccess(form) {
AdsConsent._consentForm = form;
resolve();
},
onError(error) {
reject(MobileAdsError.fromNative(error));
},
}));
});
}
}
//# sourceMappingURL=index.android.js.map