Skip to main content

GitHub Repository

iOS SDK Example

iOS SDK example project

Example Project Structure

We provide examples in three different approaches: SwiftUI, UIKit, and Objective-C.
Available in the adrop-ads-example-ios-swiftUI/ folder.This is an example implementing ads with SwiftUI-based declarative UI.

How to Run Examples

1

Clone the repository

git clone https://github.com/OpenRhapsody/adrop-ads-example-ios.git
cd adrop-ads-example-ios
2

Install dependencies

pod install
3

Open workspace

open adrop-ads-example-ios.xcworkspace
You must open .xcworkspace, not .xcodeproj.
4

Run

  1. Select a simulator or real device
  2. Run Run (⌘R)
The example project uses test unit IDs, so you can run it immediately without any additional configuration.

Key Example Code

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