Add Banner and Medium Rectangle Ads to an iOS App
Updated: Jun 30, 2026
Copy for LLM
The Audience Network allows you to monetize your iOS apps with Facebook ads. This guide explains how to create an iOS app that shows banner and medium rectangle ads.
How do I choose Medium Rectangle?
You can change placements in Monetization Manager to the Medium Rectangle format if these were previously configured as Banner for bidding. Similarly, for any new medium rectangle placements, navigate to the placement settings page in Monetization Manager and select Medium Rectangle (not Banner).
Placements will deliver as normal even if they are not changed to the medium rectangle format. However, to avoid confusion, we recommend that you change these placements to medium rectangle.
If you’re interested in other kinds of ad units, see the list of available types.
Let’s implement the following banner ad placement.

Step 1: Load and Show The Ad View
Ensure you have completed the iOS Setup Guides guide before you proceed.
When designing native ads and banner ads, ensure you have followed iOS layout guideline for optimal user experience.
-
After you have created a new project from iOS Getting Started guides, open Main.storyboard. Add a UIView element to the main View element and name it to
adContainer.
-
Now, in your View Controller header file (or Swift file, if you are a Swift user), import
FBAudienceNetwork, declare conformance to theFBAdViewDelegateprotocol, and add an instance variable for the ad unitimport UIKit import FBAudienceNetwork class ViewController: UIViewController, FBAdViewDelegate { @IBOutlet private var adContainer: UIView! private var adView: FBAdView? } -
Add the code below to
viewDidLoad; Create a new instance ofFBAdViewand add it to the view.FBAdViewis a subclass ofUIView. You can add it to your view hierarchy just like any other view.To add a Medium Rectangle ad instead, you just need to provideoverride func viewDidLoad() { super.viewDidLoad() // Instantiate an AdView object. // NOTE: the placement ID will eventually identify this as your app, you can ignore while you // are testing and replace it later when you have signed up. // While you are using this temporary code you will only get test ads and if you release // your code like this to the App Store your users will not receive ads (you will get a 'No Fill' error). let adView = FBAdView(placementID: "YOUR_PLACEMENT_ID", adSize: kFBAdSizeHeight50Banner, rootViewController: self) adView.frame = CGRect(x: 0, y: 0, width: 320, height: 250) adView.delegate = self adView.loadAd() self.adView = adView }kFBAdSizeHeight250Rectanglein the adSize parameter toFBAdView.
Audience Network supports three ad sizes to be used in yourFBAdView. A unit's width is flexible with a minimum of 320px, and only the height is defined.Ad Format AdSize Reference Size Recommendation Medium RectanglekFBAdSizeHeight 250Rectangle300x250This format is highly recommended because it provides higher performance, higher quality, and more CPU efficientStandard BannerkFBAdSizeHeight 50Banner320x50This format is suited to phones but not recommended because of poor performance and qualityLarge BannerkFBAdSizeHeight 90Banner320x90This format is suited to tablets and larger devices but not recommended because of poor performance and quality -
Replace
YOUR_PLACEMENT_IDwith your own placement id string. If you don't have a placement id or don't know how to get one, refer to the Getting Started Guide. Choose your build target to be device and run the above code, you should see something like this:
When running ads in the simulator, change the setting to test mode to view test ads. Please go to How to Use Test Mode for more information.
Step 2: Verify Impression and Click Logging
Optionally, you can add the following functions to handle the cases where the ad is closed or when the user clicks on it:
func adViewDidClick(_ adView: FBAdView) {
print("Ad was clicked.")
}
func adViewDidFinishHandlingClick(_ adView: FBAdView) {
print("Ad did finish click handling.")
}
func adViewWillLogImpression(_ adView: FBAdView) {
print("Ad impression is being captured.")
}
Step 3: How to Debug When Ad Not Shown
Add and implement the following two delegate functions in your View Controller to handle ad loading failures:
func adView(_ adView: FBAdView, didFailWithError error: Error) {
print("Ad failed to load with error: \(error.localizedDescription)")
}
func adViewDidLoad(_ adView: FBAdView) {
print("Ad was loaded and ready to be displayed")
showAd()
}
private func showAd() {
guard let adView = adView, adView.isAdValid else {
return
}
adContainer.addSubview(adView)
}
When there is no ad to show, the
adView:didFailWithError: will be called with error.code set to 1001. If you use your own custom reporting or mediation layer, you may want to check the code value and detect this case. You can fallback to another ad network in this case, but do not re-request an ad immediately after.Next steps
- Once your app has a link on the App Store or Google Play Store, configure Audience Network in Monetization Manager to get ad placement IDs.
- Follow the guides to implement ad formats in your app.
See also
- Visit our GitHub sample app repository to view sample code.
- View the Audience Network policies and the Facebook community standards to ensure your app complies.