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…
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:
- Install the package with CocoaPods or Swift Package Manager, I used the last one.
- Add in your Info.plist the GADApplicationIdentifier string key.
-
<key>GADApplicationIdentifier</key> <string>YOUR KEY</string>
-
- Add in your Info.plist the SKAdNetworkItems array key with SKAdNetworkIdentifier values for Google.
-
<key>SKAdNetworkItems</key> <array> <dict> <key>SKAdNetworkIdentifier</key> <string>cstr6suwn9.skadnetwork</string> </dict> ... </array>
-
- Add in your Info.plist the GADIsAdManagerApp bool key.
-
<key>GADIsAdManagerApp</key><true/>
-
- Initialize the Mobile Ads SDK in the AppDelegate.m file.
-
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.
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!