Hi,
I'm making an app with ionic and capacitor.
I write my own plugin for loading and displaying the ads. The ads are loaded in the plugin and passed to the app as a json, so i can load the ad in my html without any problem.
The problem comes when i have to tell the google SDK to register the click.
In the android version I found this solution from another developer online (see below) and it works fine. I tried to replicate the same code on iOS in swift, but with no results (see below); i can see the button on the screen and if click on it it triggers the ads but i can't automate the process (the ads is displayed in the html page (fine) -> the user click on an ad (fine)-> ionic tell the plugin that the ad was clicked (fine) -> the plugin trigger the ad or press on the ctaButton (not working)).
In the screenshot below you can see the ad being displayed correctly in the html page. The "iscriviti" white text is a view from the plugin I made. If i click on any element of the html ad nothing happens, but if i click on the "iscriviti" text it redirects me to the advertised page.
i must use native ads because the ads are displayed in a feed (like instagram)
Thanks
Android version
---
@PluginMethod
public void triggerNativeAd(PluginCall call) {
int id = Integer.valueOf(call.getString("id"));
getActivity()
.runOnUiThread(
new Runnable() {
@Override
public void run() {
int lId = getActivity().getResources().getIdentifier("254398", "id", getContext().getPackageName());
LinearLayout linearLayout = getActivity().findViewById(lId);
NativeAdView nativeAdView = linearLayout.findViewById(id);
AppCompatButton CTABtn = nativeAdView.findViewById(R.id.cta);
CTABtn.performClick();
}
}
);
}
---
iOS version
---
@objc func triggerNativeAd(_ call: CAPPluginCall) {
DispatchQueue.main.async {
guard let nativeAdView = self.nativeAdView,
let ctaButton = nativeAdView.callToActionView as? UIButton else {
call.reject("Native ad view or CTA button not found")
return
}
ctaButton.sendActions(for: .touchUpInside)
print("Simulated click on CTA button")
call.resolve([:])
}
}
---
![IMG_0060.PNG](https://groups.google.com/group/google-admob-ads-sdk/attach/cfe4b68331be/IMG_0060.PNG?part=0.1&view=1)