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

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


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)


Before loading ads, call the startWithCompletionHandler: method on the GADMobileAds.sharedInstance, which initializes the SDK and calls back a completion handler once initialization is complete (or after a 30-second timeout). This only needs to be done once, ideally at app launch. You should call startWithCompletionHandler: as early as possible.

Ads may be preloaded by the Mobile Ads SDK or mediation partner SDKs upon calling startWithCompletionHandler:. If you need to obtain consent from users in the European Economic Area (EEA), set any request-specific flags (such as tagForChildDirectedTreatment or tag_for_under_age_of_consent), or otherwise take action before loading ads, ensure you do so before initializing the Mobile Ads SDK.

Here's an example of how to call the startWithCompletionHandler: method in your AppDelegate:

For Swift

import GoogleMobileAds@UIApplicationMainclass AppDelegate: UIResponder, UIApplicationDelegate {  func application(_ application: UIApplication,      didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {    GADMobileAds.sharedInstance().start(completionHandler: nil)    return true  }}

For Objective-C

@import GoogleMobileAds;@implementation AppDelegate- (BOOL)application:(UIApplication *)application    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  [[GADMobileAds sharedInstance] startWithCompletionHandler:nil];  return YES;}@end

If you are using mediation, you may wish to wait until the completion handler is called before loading ads, as this will ensure that all mediation adapters are initialized.


Thank you Sr, it worked for me on Xamarin, just I need it to make some little changes on the code as follow:

GADMobileAds.SharedInstance.Start(completionHandler: null)