drop-ads 0.5.6

drop-ads 0.5.6

Leodevmartin 维护。



drop-ads 0.5.6

  • Martin、Leo 和 dev

Adrop-Ads-iOS

先决条件

  • 带有启用命令行工具的最新版本的 Xcode
  • Swift 5.0
  • ios 14.0

入门指南

1. 安装

CocoaPods

CocoaPods 是 Cocoa 项目的依赖项管理器。有关使用和安装说明,请访问他们的网站。要使用 CocoaPods 在 Xcode 项目中集成 Adrop,请将其在 Podfile 中指定。

pod 'adrop-ads'

在您的 Podfile 中添加此行

config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'      

2. 添加 adrop_service.json

Adrop 获取 adrop_service.json

将 "adrop-service.json" 添加到您的 Xcode 项目的根目录

3. 初始化

import AdropAds

@main
struct ExampleApp: App {
    init() {
        Adrop.initialize(production: false /* if release then true */)
    }
}

在生产模式为 false 时,您可以在 SDK 中检查错误日志

4. AdropBanner (必需的单位 Id,高度)

struct ContentView: View, AdropBannerDelegate {
    
    func onAdReceived(_ banner: AdropBanner) {
        print("ad received")
    }
    
    func onAdClicked(_ banner: AdropBanner) {
        print("ad clicked")
    }
    
    func onAdFailedToReceive(_ banner: AdropBanner, _ error: AdropErrorCode) {
        print("ad failed to receive, error: \(error)")
    }
    
    
    var bannerView: AdropBannerRepresented
    
    init() {
        let unitId = "ADROP_PUBLIC_TEST_UNIT_ID" // replace your unitId
        self.bannerView = AdropBannerRepresented(unitId: unitId)
        self.bannerView.banner.delegate = self
    }
    
    var body: some View {
        ZStack{
            VStack {
                Button {
                    bannerView.banner.load()
                } label: {
                    Text("requestAd")
                }
                .padding(.all)
            }
            VStack {
                Spacer()
                bannerView.frame(height: 80)
            }
        }
    }
}