blog
Ottorino Bruni  

How to solve GAD InvalidInitialization Exception crash using Google AdMob and Xcode

Every now and then I get to update some old app or implement previously used features for iPhone apps. Always I am amazed at the possible problems that can happen to and I want to talk to you about the Google Mobile Ads SDK integration
using Swift.

In my last attempt I came across this exception, whenever I start the iOS app in debug or release mode. The name should give help but instead you have to work with it. GADApplicationVerifyPublisherInitializedCorrectly

GADInvalidInitializationException

How to integrate Google Mobile Ads SDK into your Swift project?

In short these are the steps you should take to integrate Google Mobile Ads SDK into your Swift project:

  1. Install the package with CocoaPods or Swift Package Manager, I used the last one.
  2. Add in your Info.plist the GADApplicationIdentifier string key.
    1. <key>GADApplicationIdentifier</key>
      <string>YOUR KEY</string>
  3. Add in your Info.plist the SKAdNetworkItems array key with SKAdNetworkIdentifier values for Google.
    1. <key>SKAdNetworkItems</key>
      <array>
        <dict>
          <key>SKAdNetworkIdentifier</key>
          <string>cstr6suwn9.skadnetwork</string>
        </dict>
        ...
      </array>
      
      
  4. Add in your Info.plist the GADIsAdManagerApp bool key.
    1. <key>GADIsAdManagerApp</key><true/>
  5. Initialize the Mobile Ads SDK in the AppDelegate.m file.
    1. import GoogleMobileAds
      
      @UIApplicationMain
      class AppDelegate: UIResponder, UIApplicationDelegate {
      
        func application(_ application: UIApplication,
            didFinishLaunchingWithOptions launchOptions: 
      [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
      
          GADMobileAds.sharedInstance().start(completionHandler: nil)
      
          return true
        }
      }

You can find more information here. I followed all the steps in the tutorial but my app kept crashing when I started the app.

How did I solve the problem?

It was enough to complete this last step. After adding GADApplicationIdentifier & SKAdNetworkItems values in Info.plist, you have to also add -ObjC Linker Flags.

GADInvalidInitializationException objc linker flag

Open project’s build settings and search for linker. Add the -ObjC linker flag to Other Linker Flags in your project’s build settings for Debug and Release Mode.

 

If you think your friends/network would find this useful, please share it with them. I’d really appreciate it.

Thanks for reading! ????

🚀 Discover CodeSwissKnife, your all-in-one, offline toolkit for developers!

Click to explore CodeSwissKnife 👉

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.