skip to Main Content

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:

  1. create a .xib file.
  2. change the view class from UIView to GADNativeAdView.
  3. add the related components such as labels and images.
  4. connect the labels and images into the IBOutlets of GADNativeAdView.

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


  1. Chosen as BEST ANSWER

    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:

    1. Open the file containing GADNativeAdView, which is GADNativeAd.h.
    2. Select all, copy to clipboard.
    3. Create a new objective C header file in your project, give name ex: GADNativeAdCopy.h.
    4. Paste the contents from the clipboard.
    5. If you're using Swift, then import GADNativeAdCopy.h into bridging header.
    6. Now the IBOutlets of GADNativeAdView will automatically appear on Inspectors when you click on the view.
    7. Add some components, like labels and images, and connect them to some IBOutlets like headline, body, or icon.
    8. After that, remove the GADNativeAdCopy.h from the bridging header import statement. --> you need to do this otherwise your project won't compile.
    9. The .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 on ListTileNativeAdFactory.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.


  2. 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:

    <outlet property="advertiserView" destination="RQh-Yj-D46" id="HsM-vK-fec"/>
    

    Just change the destination to the id of your view and it worked for me.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search