This guide is for publishers who want to monetize an iOS app with Adgeist.
Integrating the Adgeist Mobile Ads SDK into an app is the first step toward displaying ads and earning revenue. Once you've integrated the SDK, you can proceed to implement one or more of the supported ad formats.
- Use Xcode 16.0 or higher
- Target iOS 12.0 or higher
- Recommended: Create an Adgeist publisher account and whitelist your bundle ID
Before you continue, review Using CocoaPods for information on creating and using Podfiles.
- Open your project's
Podfileand add this line to your app's target build configuration:
pod 'AdgeistKit'- In a terminal, run:
pod install --repo-update- Open your project's
.podspecand add this line to your app's target build configuration:
s.dependency "AdgeistKit", '= {{VERSION_NUMBER}}'- In a terminal, run:
pod install --repo-updateUpdate your app's Info.plist file to add three keys:
ADGEIST_API_KEY- A string value of your Adgeist mobile API key found in the Adgeist UI. (Currently required, will be deprecated in the future)ADGEIST_APP_ID- A string value of your Adgeist publisher ID found in the Adgeist UI.ADGEIST_CUSTOM_PACKAGE_OR_BUNDLE_ID- A string value of your Adgeist registered domain. (Currently required, will be deprecated in the future and retrieved directly from config)
<key>ADGEIST_API_KEY</key>
<string>{{API_KEY}}</string>
<key>ADGEIST_APP_ID</key>
<string>{{APP_ID}}</string>
<key>ADGEIST_CUSTOM_PACKAGE_OR_BUNDLE_ID</key>
<string>{{BUNDLE_ID}}</string>Note: Replace {{API_KEY}}, {{APP_ID}}, and {{BUNDLE_ID}} with your actual Adgeist API key, app ID, and bundle ID.
Before loading ads, call the initialize() method on AdgeistCore. Call this as early as possible in your app's lifecycle.
// Initialize the Adgeist Mobile Ads SDK
AdgeistCore.initialize()Banner ads are rectangular ads that occupy a portion of an app's layout. They stay on screen while users are interacting with the app, either anchored at the top or bottom of the screen or inline with content as the user scrolls.
Anchored adaptive banner ads are fixed aspect ratio ads. The aspect ratio is similar to the 320x50 industry standard.
Banner and display ads are displayed in BaseAdView objects, so the first step toward integrating ads is to include a BaseAdView in your view hierarchy. This is typically done programmatically.
A BaseAdView can also be instantiated directly. The following example creates a BaseAdView:
adView = AdView()
view.addSubview(adView)Set the AdSize struct to an anchored type with a specified width and height:
adView.setAdDimension(AdSize(width: 360, height: 360))adView.adUnitID = ADUNIT_IDReplace ADUNIT_ID with the ad unit ID you created in the Adgeist dashboard.
adView.adType = AD_TYPEReplace AD_TYPE with the ad type you created in the Adgeist dashboard (e.g., "banner", "display").
Once the BaseAdView is in place and its properties such as adUnitID, adType, and adSize are configured, it's time to load an ad. But before that, we have to create the request builder using the builder pattern below:
let request = AdRequest.AdRequestBuilder()
.setTestMode(isTestMode)
.build()When building and testing your apps, make sure you use test ads rather than live, production ads. Failure to do so can lead to suspension of your account.
The easiest way to load test ads is to use isTestMode: true when building your ad request, as shown below:
let request = AdRequest.AdRequestBuilder()
.setTestMode(true)
.build()It's been specially configured to return test ads for every request, and you're free to use it in your own apps while coding, testing, and debugging. Just make sure you replace it with isTestMode: false before publishing your app.
Now it's time to load an ad. This is done by calling loadAd: on a BaseAdView object:
adView.loadAd(request)Through the use of BaseAdViewDelegate, you can listen for lifecycle events, such as when an ad is closed or the user leaves the app.
To register for banner ad events, create a class that implements the AdListener protocol, and set an instance of that class as the listener property of your BaseAdView object:
adView.setAdListener(listeners)Each of the methods is marked as optional, so you only need to implement the methods you want. This example implements each method and logs a message to the console:
override func onAdClicked() {
print(#function)
}
override func onAdClosed() {
print(#function)
}
override func onAdFailedToLoad(_ error: String) {
print(#function)
}
override func onAdImpression() {
print(#function)
}
override func onAdLoaded() {
print(#function)
}
override func onAdOpened() {
print(#function)
}Once the SDK is initialized, you can proceed to implement ad formats supported by Adgeist Mobile Ads SDK.