Download and Integrate the Google Mobile Ads SDK

To use AdMob with your iOS project, you need to download and install the Mobile Ads SDK from Google. Visit the Mobile Ads SDK (iOS) download page[61] to download the latest version.

From within Finder, create a new folder in the project directory and name it AdMob. Unzip the downloaded SDK and copy all of the folders extracted from the zip file into the newly created AdMob folder, like so:

images/UsingAdsToIncreaseRevenue/ads-copy-sdk-files.png

Note that copying the License folder here is optional, but you should include it somewhere within your distribution.

Once you have the folders copied, you’re ready to add the frameworks to your Xcode project.

Adding the Framework

Open the gloopdrop project in Xcode.

In the Project Navigator, select the gloopdrop project file. Then, in the Project Editor, select the gloopdrop target and switch to the General tab. Scroll down until you see the Frameworks section, as shown in the image.

images/UsingAdsToIncreaseRevenue/ads-add-frameworks.png

To add a new framework, click the + button in the lower-left corner.

When the Choose frameworks and libraries to add window appears, click the Add Other... drop-down list and select Add Files..., like so:

images/UsingAdsToIncreaseRevenue/ads-select-other-frameworks.png

When prompted to select the frameworks to add, choose only the .framework folders, then click the Open button, as shown here:

images/UsingAdsToIncreaseRevenue/ads-add-frameworks-selection.png

To avoid build and runtime errors, you need switch the Embed option from Embed & Sign to Do Not Embed for all of the frameworks you just added. Use the option select arrows next to each framework to make this change, like so:

images/UsingAdsToIncreaseRevenue/ads-frameworks-do-not-embed.png

You’re almost done. Switch to the Build Settings tab and scroll down until you see the Linking section. Find the Other Linker Flags setting and double-click that line to add a new property. When the pop-up appears, enter -ObjC, like this:

images/UsingAdsToIncreaseRevenue/ads-framework-linker.png

When you add (pass) the -ObjC option to the linker, you cause it to load all members of static libraries that implement any Objective-C class or category.

To verify that everything went according to plan, expand the Other Linker Flags setting. You should see something like this:

images/UsingAdsToIncreaseRevenue/ads-framework-linker-complete.png

The last step is to import the framework into the app delegate and initialize the SDK.

Open the AppDelegate.swift file, and below the line that reads import UIKit, add the following code to import the mobile ads framework:

 import​ ​GoogleMobileAds

Then, inside the application(_:didFinishLaunchingWithOptions:) method, and just above the line that reads return true, add the following line to initialize things:

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

Finally, open the Info.plist file. Highlight the last item in the list and click the + button to add a new entry, like so:

images/UsingAdsToIncreaseRevenue/ads-plist-app-id-callouts.png

For clarity, the Key name is GADApplicationIdentifier, and the Key value is ca-app-pub-3940256099942544~1458002511. The value shown here is Google’s test app ID. You may use this ID or the one you set up earlier.

That’s it, you’re done. The Google Mobile Ads SDK is ready and waiting in your Xcode project. And while there are many ways to implement and use the SDK, you’ll use a small helper file to do most of the heavy lifting.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset