From 3d10df7126b7aabb008c0eef95c9245e8c1e05a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A6=8A=E5=8E=9F=E6=98=8C=E5=BD=A6?= Date: Tue, 10 Oct 2023 14:15:03 +0900 Subject: [PATCH] fix(): split requestTrackingAuthorization --- README.md | 36 +++++++++------ .../getcapacitor/community/admob/AdMob.java | 5 +++ ios/Plugin/Plugin.m | 1 + ios/Plugin/Plugin.swift | 44 +++++++------------ src/definitions.ts | 19 ++++---- src/web.ts | 4 ++ 6 files changed, 59 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 59978340..a98f6d39 100644 --- a/README.md +++ b/README.md @@ -296,6 +296,7 @@ AdMob.addListener(RewardAdPluginEvents.Rewarded, async () => { * [`initialize(...)`](#initialize) * [`trackingAuthorizationStatus()`](#trackingauthorizationstatus) +* [`requestTrackingAuthorization()`](#requesttrackingauthorization) * [`setApplicationMuted(...)`](#setapplicationmuted) * [`setApplicationVolume(...)`](#setapplicationvolume) * [`showBanner(...)`](#showbanner) @@ -364,6 +365,18 @@ Confirm requestTrackingAuthorization status (iOS >14) -------------------- +### requestTrackingAuthorization() + +```typescript +requestTrackingAuthorization() => Promise +``` + +request requestTrackingAuthorization (iOS >14). +This is deprecated method. We recommend UMP Consent. + +-------------------- + + ### setApplicationMuted(...) ```typescript @@ -828,14 +841,13 @@ addListener(eventName: RewardAdPluginEvents.Showed, listenerFunc: () => void) => #### AdMobInitializationOptions -| Prop | Type | Description | -| ---------------------------------- | ----------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| **`requestTrackingAuthorization`** | boolean | Use or not requestTrackingAuthorization in iOS(>14) | -| **`testingDevices`** | string[] | An Array of devices IDs that will be marked as tested devices if {@link AdMobInitializationOptions.initializeForTesting} is true (Real Ads will be served to Testing devices but they will not count as 'real'). | -| **`initializeForTesting`** | boolean | If set to true, the devices on {@link AdMobInitializationOptions.testingDevices} will be registered to receive test production ads. | -| **`tagForChildDirectedTreatment`** | boolean | For purposes of the Children's Online Privacy Protection Act (COPPA), there is a setting called tagForChildDirectedTreatment. | -| **`tagForUnderAgeOfConsent`** | boolean | When using this feature, a Tag For Users under the Age of Consent in Europe (TFUA) parameter will be included in all future ad requests. | -| **`maxAdContentRating`** | MaxAdContentRating | As an app developer, you can indicate whether you want Google to treat your content as child-directed when you make an ad request. | +| Prop | Type | Description | +| ---------------------------------- | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| **`testingDevices`** | string[] | An Array of devices IDs that will be marked as tested devices if {@link AdMobInitializationOptions.initializeForTesting} is true (Real Ads will be served to Testing devices, but they will not count as 'real'). | +| **`initializeForTesting`** | boolean | If set to true, the devices on {@link AdMobInitializationOptions.testingDevices} will be registered to receive test production ads. | +| **`tagForChildDirectedTreatment`** | boolean | For purposes of the Children's Online Privacy Protection Act (COPPA), there is a setting called tagForChildDirectedTreatment. | +| **`tagForUnderAgeOfConsent`** | boolean | When using this feature, a Tag For Users under the Age of Consent in Europe (TFUA) parameter will be included in all future ad requests. | +| **`maxAdContentRating`** | MaxAdContentRating | As an app developer, you can indicate whether you want Google to treat your content as child-directed when you make an ad request. | #### TrackingAuthorizationStatusInterface @@ -888,7 +900,7 @@ When notice listener of OnAdLoaded, you can get banner size. #### AdMobError -For more information +For more information https://developers.google.com/android/reference/com/google/android/gms/ads/AdError | Prop | Type | Description | @@ -940,7 +952,7 @@ https://developers.google.com/android/reference/com/google/android/gms/ads/AdErr #### AdMobRewardItem -For more information +For more information https://developers.google.com/admob/android/rewarded-video-adapters?hl=en | Prop | Type | Description | @@ -961,9 +973,7 @@ https://developers.google.com/admob/android/rewarded-video-adapters?hl=en From T, pick a set of properties whose keys are in the union K -{ - [P in K]: T[P]; - } +{ [P in K]: T[P]; } ### Enums diff --git a/android/src/main/java/com/getcapacitor/community/admob/AdMob.java b/android/src/main/java/com/getcapacitor/community/admob/AdMob.java index cbd247a4..a63193b9 100644 --- a/android/src/main/java/com/getcapacitor/community/admob/AdMob.java +++ b/android/src/main/java/com/getcapacitor/community/admob/AdMob.java @@ -74,6 +74,11 @@ public void onInitializationComplete(InitializationStatus initializationStatus) } } + @PluginMethod + public void requestTrackingAuthorization(final PluginCall call) { + call.resolve(); + } + @PluginMethod public void trackingAuthorizationStatus(final PluginCall call) { JSObject response = new JSObject(); diff --git a/ios/Plugin/Plugin.m b/ios/Plugin/Plugin.m index ee8a4d1d..d13a3008 100644 --- a/ios/Plugin/Plugin.m +++ b/ios/Plugin/Plugin.m @@ -7,6 +7,7 @@ CAP_PLUGIN_METHOD(initialize, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(trackingAuthorizationStatus, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(requestConsentInfo, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(requestTrackingAuthorization, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(showConsentForm, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(resetConsentInfo, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(setApplicationMuted, CAPPluginReturnPromise); diff --git a/ios/Plugin/Plugin.swift b/ios/Plugin/Plugin.swift index dcf10392..33dbd033 100644 --- a/ios/Plugin/Plugin.swift +++ b/ios/Plugin/Plugin.swift @@ -29,57 +29,45 @@ public class AdMob: CAPPlugin { GADMobileAds.sharedInstance().start(completionHandler: nil) call.resolve([:]) } - + /** * DEPRECATED: It's now ship with Admob UMP Consent */ @objc func requestTrackingAuthorization(_ call: CAPPluginCall) { - let isTrack = call.getBool("requestTrackingAuthorization") ?? true - - if !isTrack { - GADMobileAds.sharedInstance().start(completionHandler: nil) - call.resolve([:]) - } else if #available(iOS 14, *) { + if #available(iOS 14, *) { #if canImport(AppTrackingTransparency) ATTrackingManager.requestTrackingAuthorization(completionHandler: { _ in - // iOS >= 14 - GADMobileAds.sharedInstance().start(completionHandler: nil) call.resolve([:]) - }) #else - GADMobileAds.sharedInstance().start(completionHandler: nil) call.resolve([:]) #endif } else { - // iOS < 14 - GADMobileAds.sharedInstance().start(completionHandler: nil) call.resolve([:]) } } - + @objc func setApplicationMuted(_ call: CAPPluginCall) { if let shouldMute = call.getBool("muted") { GADMobileAds.sharedInstance().applicationMuted = shouldMute call.resolve([:]) } else { - call.reject("muted property cannot be null"); - return; + call.reject("muted property cannot be null") + return } } - + @objc func setApplicationVolume(_ call: CAPPluginCall) { if var volume = call.getFloat("volume") { - //Clamp volumes. - if (volume < 0.0) {volume = 0.0} - else if (volume > 1.0) {volume = 1.0} - + //Clamp volumes. + if volume < 0.0 {volume = 0.0} else if volume > 1.0 {volume = 1.0} + GADMobileAds.sharedInstance().applicationVolume = volume call.resolve([:]) } else { - call.reject("volume property cannot be null"); - return; + call.reject("volume property cannot be null") + return } } @@ -176,14 +164,14 @@ public class AdMob: CAPPlugin { } } } - + /** * Admob: User Message Platform * https://support.google.com/admob/answer/10113005?hl=en */ @objc func requestConsentInfo(_ call: CAPPluginCall) { let debugGeography = call.getInt("debugGeography", 0) - + let testDeviceJSArray = call.getArray("testDeviceIdentifiers") ?? [] var testDeviceIdentifiers: [String] = [] if testDeviceJSArray.count > 0 { @@ -193,20 +181,20 @@ public class AdMob: CAPPlugin { } } } - + let tagForUnderAgeOfConsent = call.getBool("tagForUnderAgeOfConsent", false) DispatchQueue.main.async { self.consentExecutor.requestConsentInfo(call, debugGeography, testDeviceIdentifiers, tagForUnderAgeOfConsent) } } - + @objc func showConsentForm(_ call: CAPPluginCall) { DispatchQueue.main.async { self.consentExecutor.showConsentForm(call) } } - + @objc func resetConsentInfo(_ call: CAPPluginCall) { DispatchQueue.main.async { self.consentExecutor.resetConsentInfo(call) diff --git a/src/definitions.ts b/src/definitions.ts index 52ee28c3..cbfd8cc7 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -27,6 +27,15 @@ export interface AdMobPlugin extends AdMobDefinitions { */ trackingAuthorizationStatus(): Promise; + /** + * request requestTrackingAuthorization (iOS >14). + * This is deprecated method. We recommend UMP Consent. + * + * @see https://developer.apple.com/documentation/apptrackingtransparency/attrackingmanager/3547038-trackingauthorizationstatus + * @since 5.2.0 + */ + requestTrackingAuthorization(): Promise; + /** * Report application mute state to AdMob SDK * @@ -45,17 +54,9 @@ export interface AdMobPlugin extends AdMobDefinitions { } export interface AdMobInitializationOptions { - /** - * Use or not requestTrackingAuthorization in iOS(>14) - * - * @see https://developer.apple.com/documentation/apptrackingtransparency/attrackingmanager/3547037-requesttrackingauthorization?changes=latest_minor - * @since 1.1.2 - */ - requestTrackingAuthorization?: boolean; - /** * An Array of devices IDs that will be marked as tested devices if {@link AdMobInitializationOptions.initializeForTesting} is true - * (Real Ads will be served to Testing devices but they will not count as 'real'). + * (Real Ads will be served to Testing devices, but they will not count as 'real'). * * @see https://developers.google.com/admob/android/test-ads#enable_test_devices * @since 1.2.0 diff --git a/src/web.ts b/src/web.ts index d1ed9dd0..b6bd3363 100644 --- a/src/web.ts +++ b/src/web.ts @@ -28,6 +28,10 @@ export class AdMobWeb extends WebPlugin implements AdMobPlugin { console.log('targetSettings'); } + async requestTrackingAuthorization(): Promise { + console.log('requestTrackingAuthorization'); + } + async trackingAuthorizationStatus(): Promise { return { status: 'authorized',