Integrating Facebook Ads SDK with Banner Ads and Interstitial Ads
In this tutorial, we will integrate the Facebook Ads SDK with banner ads and interstitial ads. We will be using Swift 3 and Xcode 8.
First, we will create a new project in Xcode. We will select the Single View Application template and name the project “FacebookAdsDemo”.
Next, we will add the Facebook Ads SDK to our project. We can do this by opening the terminal and running the following command:
sudo gem install facebook-sdk
Next, we will open the Facebook Ads SDK file and add the following code:
import FacebookAds
We will also need to add the following code to our AppDelegate.swift file:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FBAds.shared().delegate = self
return true
}
We will also need to add the following code to our ViewController.swift file:
override func viewDidLoad() {
super.viewDidLoad()
FBAds.shared().load(
banner: nil,
interstitial: nil,
)
}
We will also need to add the following code to our ViewController.swift file:
func bannerView(_ bannerView: UIView, didLoad adUnitID: String) {
print(“Banner View Loaded”)
}
func interstitialView(_ interstitialView: UIView, didLoad adUnitID: String) {
print(“Interstitial View Loaded”)
}
We can now run our project in the simulator or on a device. When we run our project, we should see the following output:
Banner View Loaded
Interstitial View Loaded