GitHub Repository
iOS SDK Example
iOS SDK example project
Example Project Structure
We provide examples in three different approaches: SwiftUI, UIKit, and Objective-C.
SwiftUI
UIKit
Objective-C
Available in the adrop-ads-example-ios-swiftUI/ folder.This is an example implementing ads with SwiftUI-based declarative UI.
Available in the adrop-ads-example-ios/ folder.This is an example implementing ads with UIKit-based traditional approach.
Available in the adrop-ads-example-ios-objective-c/ folder.This is an example implementing ads with Objective-C.
How to Run Examples
Clone the repository
git clone https://github.com/OpenRhapsody/adrop-ads-example-ios.git
cd adrop-ads-example-ios
Open workspace
open adrop-ads-example-ios.xcworkspace
You must open .xcworkspace, not .xcodeproj.
Run
- Select a simulator or real device
- Run Run (⌘R)
The example project uses test unit IDs, so you can run it immediately without any additional configuration.
Key Example Code
Banner Ad (SwiftUI)
import SwiftUI
import AdropAds
struct BannerExample: View {
var body: some View {
AdropBannerView(unitId: "PUBLIC_TEST_UNIT_ID_320_50")
.frame(width: 320, height: 50)
}
}
Interstitial Ad (UIKit)
import UIKit
import AdropAds
class InterstitialViewController: UIViewController, AdropInterstitialAdDelegate {
var interstitialAd: AdropInterstitialAd?
override func viewDidLoad() {
super.viewDidLoad()
interstitialAd = AdropInterstitialAd(unitId: "PUBLIC_TEST_UNIT_ID_INTERSTITIAL")
interstitialAd?.delegate = self
interstitialAd?.load()
}
func onAdReceived(_ ad: AdropInterstitialAd) {
if ad.isLoaded {
ad.show(fromRootViewController: self)
}
}
func onAdFailedToReceive(_ ad: AdropInterstitialAd, _ errorCode: AdropErrorCode) {
print("Failed: \(errorCode)")
}
}
Interstitial Ad (Objective-C)
@import AdropAds;
@interface InterstitialViewController () <AdropInterstitialAdDelegate>
@property (nonatomic, strong) AdropInterstitialAd *interstitialAd;
@end
@implementation InterstitialViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.interstitialAd = [[AdropInterstitialAd alloc] initWithUnitId:@"PUBLIC_TEST_UNIT_ID_INTERSTITIAL"];
self.interstitialAd.delegate = self;
[self.interstitialAd load];
}
- (void)onAdReceived:(AdropInterstitialAd *)ad {
if (ad.isLoaded) {
[ad showFromRootViewController:self];
}
}
- (void)onAdFailedToReceive:(AdropInterstitialAd *)ad :(AdropErrorCode)errorCode {
NSLog(@"Failed: %ld", (long)errorCode);
}
@end