What is the most recent correct syntax to initialize the Google Mobile Ads SDK in the App Delegate file?
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.