Search code examples
xcodeswift4

What is the most recent correct syntax to initialize the Google Mobile Ads SDK in the App Delegate file?


All of a sudden, I get a warning on the code used to initialize the Google Mobile Ads SDK. (It had been working for weeks before with no warning, but now it seems there's a new way to write the code.)

This is the code I have:

GADMobileAds.configure(withApplicationID: "ca-app-pub-################~##########")

But it gives me this warning: 'configure(withApplicationID:)' is deprecated: Use [GADMobileAds.sharedInstance startWithCompletionHandler:]

I've tried to rewrite it like this (with and without the square brackets):

GADMobileAds.sharedInstance startWithCompletionHandler: "ca-app-pub-################~##########"

But it just gives me an error that it expected a ;.

How should I write this? Thank you!

files from Pods folder in Xcode show a modified status


Solution

  • 1) Add the follow in Info.plist

    <key>GADApplicationIdentifier</key>
    <string>ca-app-pub-3940256099942544~1458002511</string>
    

    2) in AppDelegate

     GADMobileAds.sharedInstance().start(completionHandler: nil)