I’m implementing Google Admob on Flutter using this tutorial for general steps, then and then this tutorial for a specific tutorial on GADNativeAdView
. The tutorial shows about how developers should:
- create a
.xib
file. - change the view class from UIView to GADNativeAdView.
- add the related components such as labels and images.
- connect the labels and images into the
IBOutlet
s ofGADNativeAdView
.
But when I arrived to step 4, I’m confused because I don’t see any outlets on GADNativeAdView
. When I open the source code of GADNativeAd.h
containing GADNativeAdView
, I see clearly that the interface GADNativeAdView
obviously contains outlets. But it doesn’t show on the Inspectors. How can I do this?
2
Answers
After much looking around, I arrive at this comment on this answer to this question, which points to a google group discussion about the same thing in 2021. In a reply, Google developer said that they're aware of this issue, which is basically Apple's problem, and there's nothing they can do about it except wait for Apple to fix it. Read the whole thread for the entire story.
But to work around this issue, here are the steps:
GADNativeAdView
, which isGADNativeAd.h
.GADNativeAdCopy.h
.GADNativeAdCopy.h
into bridging header.IBOutlet
s ofGADNativeAdView
will automatically appear on Inspectors when you click on the view.GADNativeAdCopy.h
from the bridging header import statement. --> you need to do this otherwise your project won't compile..xib
GADNativeAdView
view will still retain its outlets even after you remove the import statement. (the import statement only needed to make the outlets appear, so if the other unconnected outlets suddenly disappear, just re-add the bridging header import)Note: You will still need to
import google_mobile_ads
onListTileNativeAdFactory.swift
.This is a Question and Answer post to let other users know the solution, because the right search results don't appear easily when I scoured the web earlier.
In 2023 Google has provided a xib file here. If you’re starting from scratch or heavily modified the file like I did and deleted some views and their outlets, you can copy/paste the outlets from the NativeAdView.xib file from Google:
Just change the destination to the id of your view and it worked for me.