Saturday, March 11, 2017

Steps to replace apple iAd to google adMob in xcode project

Since apple stops support of iAd, so existing ios apps published in app store need to be updated to using google adMob to earn ad income.

The below steps are how to make the switch:
1. open xcode project remove iAd framework and any related code
2. install cocoapod on mac if not yet installed before
3. register to google adMob account at
https://apps.admob.com/#home
4. from adMob home screen, select Mobilize tab, and click the "mobilize new app" button. Then select the app store app you already published and create an adMob app.
5. In step 3, create a google firebase project.  it will give you a link to download the googleservice-info.plist file. The config file is also available in firebase web page at
https://firebase.google.com
6. cd into xcode project and create pod file as below and be sure to update the target to the right one
source 'https://github.com/CocoaPods/Specs.git
platform :ios, '7.0'

target 'YourProjectTarget' do

  use_frameworks!
  pod 'Firebase/Core'
  pod 'Firebase/AdMob'

end
7. run pod update to add the firebase framework into your xcode project
8. open the newly created xcode xcworkspace from xcode
9. add the previous step 5's plist file into the project
10. update xcode project storyboard to add ad view as described at
https://firebase.google.com/docs/admob/ios/quick-start
Basically, you will need to add UIView in the viewcontroller, and put the view at the bottom of the viewcontroller, and then update the viewcontroller code to made request to server to get the ads
11. To avoid the compile error, add the below import to the related source file

import GoogleMobileAds
import UIKit
12 In case you get a wired error of fail to run the app on real ios device, try http://jonathanblog2000.blogspot.ca/2017/03/ios-xcode-fix-framework-not-load-with.html
13. check appdelegate.swift to have the right admob appid, and all view controller to have right ad unit id.

After a while, when you build the ios project, you may get a warning of
"Please consider updating your SDK to the most recent SDK version to get the latest features and bug fixes."
In order to update the google sdk version, from mac terminal, goto the project folder and run
pod update
The above command will update google sdk to the latest version, and avoid the version update warning.

No comments:

Post a Comment