Consent sharing with WebView
This guide explains how to use the consent-sharing functionality through the APIs provided in the Android and iOS SDKs. The implementation allows synchronization of consent data between your application and a WebView via a JavaScript script. The APIs described below are available starting from version v3.X.X of the Android and iOS SDKs.
In the Android SDK, consent can be managed using the `cmp` object and the `onConsentReady` method. Once the consent API is ready, a `consentApiInterface` is provided, which can be used to obtain the necessary JavaScript to pass as a parameter to the WebView's `evaluateJavascript`. Below is an example:
In the iOS SDK, consent is managed through PubConsentCMP.shared. Once the consent API is ready, a consentApiInterface is provided, which can be used to obtain the necessary JavaScript to pass as a parameter to the WebView's evaluateJavascript.
Since delays might occur, you can prevent the CMP from appearing in your WebView by adding the following query string to the URL: ?pubconsent.waitForExternalConsent=1
This will block the CMP from appearing in the WebView. Instead, the CMP in the WebView will wait for the consent to be shared using the APIs described above.