UNPKG

@nativescript/google-mobile-ads

Version:
108 lines 4.25 kB
import { MobileAdsError } from '../error'; import { topViewController } from '../utils'; import { AdsConsentBase, AdsConsentDebugGeography, AdsConsentStatus } from './common'; export { AdsConsentStatus, AdsConsentDebugGeography }; export class AdsConsent extends AdsConsentBase { static reset() { UMPConsentInformation.sharedInstance.reset(); } static addTestDevices(deviceIds) { this._deviceIds = deviceIds; } static getStatus() { switch (UMPConsentInformation.sharedInstance.consentStatus) { case 2 /* UMPConsentStatus.NotRequired */: return AdsConsentStatus.NOT_REQUIRED; case 3 /* UMPConsentStatus.Obtained */: return AdsConsentStatus.OBTAINED; case 1 /* UMPConsentStatus.Required */: return AdsConsentStatus.REQUIRED; case 0 /* UMPConsentStatus.Unknown */: return AdsConsentStatus.UNKNOWN; } } static requestInfoUpdate() { return new Promise((resolve, reject) => { const request = UMPRequestParameters.new(); switch (this._geography) { case AdsConsentDebugGeography.DISABLED: request.debugSettings.geography = 0 /* UMPDebugGeography.Disabled */; break; case AdsConsentDebugGeography.EEA: request.debugSettings.geography = 1 /* UMPDebugGeography.EEA */; break; case AdsConsentDebugGeography.NOT_EEA: request.debugSettings.geography = 2 /* UMPDebugGeography.NotEEA */; break; } if (Array.isArray(this._deviceIds)) { request.debugSettings.testDeviceIdentifiers = this._deviceIds.map((item) => { if (item === 'EMULATOR') { if (global.GADSimulatorID) { return GADSimulatorID; } return ''; } return item; }); } if (typeof this._tagForUnderAgeOfConsent === 'boolean') { request.tagForUnderAgeOfConsent = this._tagForUnderAgeOfConsent; } UMPConsentInformation.sharedInstance.requestConsentInfoUpdateWithParametersCompletionHandler(request, (error) => { if (error) { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore reject(MobileAdsError.fromNative(error)); } else { resolve(); } }); }); } static setDebugGeography(geography) { this._geography = geography; } static setTagForUnderAgeOfConsent(tag) { this._tagForUnderAgeOfConsent = tag; } static isConsentFormAvailable() { switch (UMPConsentInformation.sharedInstance.formStatus) { case 1 /* UMPFormStatus.Available */: return true; default: return false; } } static showForm() { return new Promise((resolve, reject) => { this._consentForm.presentFromViewControllerCompletionHandler(topViewController(), (error) => { if (error) { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore reject(MobileAdsError.fromNative(error)); } else { resolve(); } }); }); } static loadForm() { return new Promise((resolve, reject) => { UMPConsentForm.loadWithCompletionHandler((form, error) => { if (error) { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore reject(MobileAdsError.fromNative(error)); } else { AdsConsent._consentForm = form; resolve(); } }); }); } } //# sourceMappingURL=index.ios.js.map