Skip to content

Commit

Permalink
fix(consent): fix ios dismiss error
Browse files Browse the repository at this point in the history
  • Loading branch information
rdlabo committed Aug 30, 2023
1 parent 94681b2 commit c0f8007
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions ios/Plugin/Consent/ConsentExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,60 @@ import Capacitor
import GoogleMobileAds
import UserMessagingPlatform


class ConsentExecutor: NSObject {
public weak var plugin: AdMob?

func requestConsentInfo(_ call: CAPPluginCall, _ debugGeography: Int, _ testDeviceIdentifiers: Array<String>, _ tagForUnderAgeOfConsent: Bool) {
func requestConsentInfo(_ call: CAPPluginCall, _ debugGeography: Int, _ testDeviceIdentifiers: [String], _ tagForUnderAgeOfConsent: Bool) {
let parameters = UMPRequestParameters()
let debugSettings = UMPDebugSettings()

debugSettings.geography = UMPDebugGeography(rawValue: debugGeography) ?? UMPDebugGeography.disabled
debugSettings.testDeviceIdentifiers = testDeviceIdentifiers

parameters.debugSettings = debugSettings
parameters.tagForUnderAgeOfConsent = tagForUnderAgeOfConsent

// Request an update to the consent information.
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(
with: parameters,
completionHandler: { error in
if error != nil {
call.reject("Request consent info failed")
} else {
call.resolve([
"status": self.getConsentStatusString(UMPConsentInformation.sharedInstance.consentStatus),
"isConsentFormAvailable": UMPConsentInformation.sharedInstance.formStatus == UMPFormStatus.available
])
}
})
with: parameters,
completionHandler: { error in
if error != nil {
call.reject("Request consent info failed")
} else {
call.resolve([
"status": self.getConsentStatusString(UMPConsentInformation.sharedInstance.consentStatus),
"isConsentFormAvailable": UMPConsentInformation.sharedInstance.formStatus == UMPFormStatus.available
])
}
})
}

func showConsentForm(_ call: CAPPluginCall) {
if let rootViewController = plugin?.getRootVC() {
let formStatus = UMPConsentInformation.sharedInstance.formStatus

if formStatus == UMPFormStatus.available {
UMPConsentForm.load(completionHandler: {form, loadError in
if loadError != nil {
call.reject(loadError?.localizedDescription ?? "Load consent form error")
} else {
if UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatus.required {
form?.present(from: rootViewController, completionHandler: { dismissError in
if (dismissError != nil) {
call.resolve([
"status": self.getConsentStatusString(UMPConsentInformation.sharedInstance.consentStatus),
])
} else {
call.reject(dismissError?.localizedDescription ?? "Consent dismiss error")
return
}

if UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatus.required {
form?.present(from: rootViewController, completionHandler: { dismissError in
if dismissError != nil {
call.reject(dismissError?.localizedDescription ?? "Consent dismiss error")
return
}

}
})
} else {
call.resolve([
"status": self.getConsentStatusString(UMPConsentInformation.sharedInstance.consentStatus),
"status": self.getConsentStatusString(UMPConsentInformation.sharedInstance.consentStatus)
])
}
})
} else {
call.resolve([
"status": self.getConsentStatusString(UMPConsentInformation.sharedInstance.consentStatus)
])
}
})
} else {
Expand All @@ -71,17 +71,17 @@ class ConsentExecutor: NSObject {
UMPConsentInformation.sharedInstance.reset()
call.resolve()
}

func getConsentStatusString(_ consentStatus: UMPConsentStatus) -> String {
switch (consentStatus) {
switch consentStatus {
case UMPConsentStatus.required:
return "REQUIRED";
return "REQUIRED"
case UMPConsentStatus.notRequired:
return "NOT_REQUIRED";
return "NOT_REQUIRED"
case UMPConsentStatus.obtained:
return "OBTAINED";
return "OBTAINED"
default:
return "UNKNOWN";
return "UNKNOWN"
}
}
}

0 comments on commit c0f8007

Please sign in to comment.