Skip to content

Commit

Permalink
fix(): split requestTrackingAuthorization
Browse files Browse the repository at this point in the history
  • Loading branch information
rdlabo committed Oct 10, 2023
1 parent f3ee995 commit 3d10df7
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 50 deletions.
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ AdMob.addListener(RewardAdPluginEvents.Rewarded, async () => {

* [`initialize(...)`](#initialize)
* [`trackingAuthorizationStatus()`](#trackingauthorizationstatus)
* [`requestTrackingAuthorization()`](#requesttrackingauthorization)
* [`setApplicationMuted(...)`](#setapplicationmuted)
* [`setApplicationVolume(...)`](#setapplicationvolume)
* [`showBanner(...)`](#showbanner)
Expand Down Expand Up @@ -364,6 +365,18 @@ Confirm requestTrackingAuthorization status (iOS >14)
--------------------


### requestTrackingAuthorization()

```typescript
requestTrackingAuthorization() => Promise<void>
```

request requestTrackingAuthorization (iOS &gt;14).
This is deprecated method. We recommend UMP Consent.

--------------------


### setApplicationMuted(...)

```typescript
Expand Down Expand Up @@ -828,14 +841,13 @@ addListener(eventName: RewardAdPluginEvents.Showed, listenerFunc: () => void) =>

#### AdMobInitializationOptions

| Prop | Type | Description |
| ---------------------------------- | ----------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`requestTrackingAuthorization`** | <code>boolean</code> | Use or not requestTrackingAuthorization in iOS(&gt;14) |
| **`testingDevices`** | <code>string[]</code> | An Array of devices IDs that will be marked as tested devices if {@link <a href="#admobinitializationoptions">AdMobInitializationOptions.initializeForTesting</a>} is true (Real Ads will be served to Testing devices but they will not count as 'real'). |
| **`initializeForTesting`** | <code>boolean</code> | If set to true, the devices on {@link <a href="#admobinitializationoptions">AdMobInitializationOptions.testingDevices</a>} will be registered to receive test production ads. |
| **`tagForChildDirectedTreatment`** | <code>boolean</code> | For purposes of the Children's Online Privacy Protection Act (COPPA), there is a setting called tagForChildDirectedTreatment. |
| **`tagForUnderAgeOfConsent`** | <code>boolean</code> | 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`** | <code><a href="#maxadcontentrating">MaxAdContentRating</a></code> | 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`** | <code>string[]</code> | An Array of devices IDs that will be marked as tested devices if {@link <a href="#admobinitializationoptions">AdMobInitializationOptions.initializeForTesting</a>} is true (Real Ads will be served to Testing devices, but they will not count as 'real'). |
| **`initializeForTesting`** | <code>boolean</code> | If set to true, the devices on {@link <a href="#admobinitializationoptions">AdMobInitializationOptions.testingDevices</a>} will be registered to receive test production ads. |
| **`tagForChildDirectedTreatment`** | <code>boolean</code> | For purposes of the Children's Online Privacy Protection Act (COPPA), there is a setting called tagForChildDirectedTreatment. |
| **`tagForUnderAgeOfConsent`** | <code>boolean</code> | 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`** | <code><a href="#maxadcontentrating">MaxAdContentRating</a></code> | 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
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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 |
Expand All @@ -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

<code>{
[P in K]: T[P];
}</code>
<code>{ [P in K]: T[P]; }</code>


### Enums
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions ios/Plugin/Plugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
44 changes: 16 additions & 28 deletions ios/Plugin/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
19 changes: 10 additions & 9 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ export interface AdMobPlugin extends AdMobDefinitions {
*/
trackingAuthorizationStatus(): Promise<TrackingAuthorizationStatusInterface>;

/**
* 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<void>;

/**
* Report application mute state to AdMob SDK
*
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export class AdMobWeb extends WebPlugin implements AdMobPlugin {
console.log('targetSettings');
}

async requestTrackingAuthorization(): Promise<void> {
console.log('requestTrackingAuthorization');
}

async trackingAuthorizationStatus(): Promise<TrackingAuthorizationStatusInterface> {
return {
status: 'authorized',
Expand Down

0 comments on commit 3d10df7

Please sign in to comment.