Bridgewell iOS SDK。
版本:1.0
如果您不熟悉使用 Cocoapods 进行依赖管理,请访问他们的 入门页面。一旦您设置了 Podfile,请包括以下内容
target 'MyAmazingApp' do
pod 'BridgewellSDK'
end
现在运行 pod install
将 Bridgewell SDK 添加到项目依赖项。
更新您的应用 Info.plist
文件以添加此键:GADApplicationIdentifier
,字符串值为您的 AdMob 应用 ID(可在 AdMob UI 中找到找到)。
<key>GADApplicationIdentifier</key>
<string>{{YOUR-KEY}}</string>
首先您必须导入 SDK 以设置它,通常在 AppDelegate
import BridgewellSDK
import PrebidMobile
import GoogleMobileAds
import PrebidMobileAdMobAdapters
import PrebidMobileGAMEventHandlers
一旦您有一个 Bridgewell 服务器,您将其添加到 BW 移动。例如,如果您正在使用 AppNexus 服务器。
Bridgewell.shared.bridgewellServerAccountId = YOUR_ACCOUNT_ID
Bridgewell.shared.bridgewellServerHost = YOUR_SERVER_HOST
如果您选择托管自己的 BW 服务器解决方案,则需要存储服务器 URL 到您的应用中。确保您的 URL 指向 /openrtb2/auction 端点。
try? Bridgewell.shared.setCustomBridgewellServer(url: YOUR_CUSTOM_HOST_SERVER)
如果提供的 URL 无效,则此方法会抛出异常。
在您有了账号 ID 和托管服务器之后。您应按如下方式初始化 BW SDK
一旦设置账号 ID 和 BW 服务器主机,您应初始化 BW SDK。有多种初始化方式。
如果您使用与 GMA SDK 版本等于或高于 10.7.0 集成 Bridgewell,请使用以下初始化器,该初始化器会检查 Bridgewell SDK 与用于应用的 GMA SDK 的兼容性
Bridgewell.initializeSDK(gadMobileAdsVersion: GADGetStringFromVersionNumber(GADMobileAds.sharedInstance().versionNumber) { status, error in
switch status {
case .succeeded:
print("Bw SDK successfully initialized")
case .failed:
if let error = error {
print("An error occurred during Bw SDK initialization: \(error.localizedDescription)")
}
case .serverStatusWarning:
if let error = error {
print("Bw Server status checking failed: \(error.localizedDescription)")
}
default:
break
}
}
如果您使用小于 10.7.0 版本的 GMA SDK 集成 Bridgewell SDK,请使用以下初始化器
Bridgewell.initializeSDK(GADMobileAds.sharedInstance()) { status, error in
switch status {
case .succeeded:
print("Bridgewell SDK successfully initialized")
case .failed:
if let error = error {
print("An error occurred during Bridgewell SDK initialization: \(error.localizedDescription)")
}
case .serverStatusWarning:
if let error = error {
print("Bridgewell Server status checking failed: \(error.localizedDescription)")
}
default:
break
}
}
检查应用程序的日志消息。如果提供的 GMA SDK 版本未通过兼容性验证,Bridgewell SDK 会通知您。
对于无广告服务器的情况,请使用以下初始化
Bridgewell.initializeSDK { status, error in
// ....
}
在初始化期间,SDK 创建内部类并将健康检查请求发送到 /status 端点。如果您使用自定义 PBS 服务器,您还应该提供自定义的健康检查端点
Bridgewell.shared.customStatusEndpoint = BRIDGEWELL_SERVER_STATUS_ENDPOINT
如果请求出现错误,初始化回调的状态将是 .serverStatusWarning
。它不影响 SDK 流程,只是通知您关于健康检查结果。
Bridgewell
类是一个单例,它允许用户应用全局设置。
bridgewellServerAccountId
:包含 Bridgewell 服务器账号 ID 的字符串。
bridgewellServerHost
:包含配置 Bridgewell 服务器主机,该主机将用于 Bridgewell SDK 的通信。从系统定义的 Bridgewell 服务器主机中选择,或定义您自己的自定义 Bridgewell 服务器主机。
shareGeocoordinate
: 可选布尔值,如果此标志为True并且应用收集用户的地理位置数据,Bridgewell Mobile将向Bridgewell服务器发送用户的位置数据。如果此标志为False或应用不收集用户的位置数据,Bridgewell Mobile在调用Bridgewell服务器时将不会包含任何用户地理位置信息。默认设置是false。
logLevel
: 可选日志输出级别,以在控制台上创建。选项是以下按日志详略度排序的其中一个:
public static let debug = LogLevel(stringValue: "[💬]", rawValue: 0)
public static let verbose = LogLevel(stringValue: "[🔬]", rawValue: 1)
public static let info = LogLevel(stringValue: "[ℹ️]", rawValue: 2)
public static let warn = LogLevel(stringValue: "[⚠️]", rawValue: 3)
public static let error = LogLevel(stringValue: "[‼️]", rawValue: 4)
public static let severe = LogLevel(stringValue: "[🔥]", rawValue: 5)
timeoutMillis
: Bridgewell超时(可供Bridgewell SDK 1.2+访问),以毫秒为单位,将在达到过期时间后返回控制权给广告服务器SDK以获取广告。因为Bridgewell SDK通过一个数据包从Bridgewell服务器请求报价,设置Bridgewell超时太低可能会阻碍所有需求,从而可能对收入产生负面影响。
creativeTimeout
: 控制横幅创意加载多长时间后被认为是失败。
creativeTimeoutPreRenderContent
: 控制视频和插屏创意加载多长时间后被认为是失败。
cachedAuctionResponse
: 设置为字符串类型,存储的拍卖响应通知Bridgewell服务器根据Bridgewell服务器数据库中找到的存储aucti
bwsDebug
: 向Bridgewell服务器的外出HTTP调用添加调试标志(“test”:1)。test:1标志将通知Bridgewell服务器输出完整的解析请求(解决任何存储请求ID),以及每个出价者之间的完整出价请求和出价响应。
addStoredBidResponse:包含两个属性的函数
bidder:出价者名称,由Bridgewell服务器出价适配器定义为字符串类型。responseId:Bridgewell服务器数据库中使用的配置ID,用于存储静态出价响应。存储的出价响应类似于存储的拍卖响应,因为它们都向Bridgewell服务器发出响应以使用静态预定义响应的信号,不同的是存储的出价响应在出价者级别执行,发送给任何未在出价者参数中指定的出价者的出价请求。有关存储拍卖响应如何工作的更多信息
func addStoredBidResponse(bidder: String, responseId: String)
clearStoredBidResponses:清除任何存储的出价响应。
func clearStoredBidResponses()
以下方法使您能够自定义调用Bridgewell服务器上的HTTP调用:
func addCustomHeader(name: String, value: String)
func clearCustomHeaders()
// Host
Bridgewell.shared.BridgewellServerHost = .Rubicon
// or set a custom host
Bridgewell.shared.BridgewellServerHost = BridgewellHost.Custom
do {
try Bridgewell.shared.setCustomBridgewellServer(url: "https://Bridgewell-server.customhost.com")
} catch {
print(error)
}
// Account Id
Bridgewell.shared.BridgewellServerAccountId = "1234"
// Geolocation
Bridgewell.shared.shareGeoLocation = true
// Log level data
Bridgewell.shared.logLevel = .verbose
// Set Bridgewell timeout in milliseconds
Bridgewell.shared.timeoutMillis = 3000
// Enable Bridgewell Server debug respones
Bridgewell.shared.pbsDebug = true
// Stored responses can be one of storedAuction response or storedBidResponse
Bridgewell.shared.storedAuctionResponse = "111122223333"
//or
Bridgewell.shared.addStoredBidResponse(bidder: "appnexus", responseId: "221144")
Bridgewell.shared.addStoredBidResponse(bidder: "rubicon", responseId: "221155")
您可以使用Bridgewell SDK通过自定义广告服务器或甚至没有它来盈利您的应用。使用渲染API在不使用主广告服务器及其SDK的情况下显示获胜投标。
集成示例:
// 1. Create an Ad View
let banner = BannerView(frame: CGRect(origin: .zero, size: adSize),
configID: CONFIG_ID,
adSize: adSize)
banner.delegate = self
// 2. Load an Ad
banner.loadAd()
步骤1:创建广告视图
使用属性初始化横幅广告视图
- frame - 视图的框架矩形
- configID - Bridgewell服务器上存储的曝光ID
- size - 将在出价请求中使用的广告单元的大小
步骤2:加载广告
调用方法loadAd(),它将
- 向Bridgewell服务器发送出价请求。
- 在显示上渲染获胜投标。
横幅视频:
对于横幅视频,您还需要指定广告格式:
banner.adFormat = .video
集成示例:
// 1. Create an Interstitial Ad Unit
interstitial = InterstitialRenderingAdUnit(configID: CONFIG_ID,
minSizePercentage: CGSize(width: 30, height: 30))
interstitial.delegate = self
// 2. Load an Ad
interstitial.loadAd()
// .....
// 3. Show An Ad
if interstitial.isReady {
interstitial.show(from: self)
}
插屏的默认广告格式是 .banner。为了制作多格式出价请求,将相应的值设置为adFormats属性。
// Make bid request for video ad
adUnit?.adFormats = [.video]
// Make bid request for both video and banner ads
adUnit?.adFormats = [.video, .banner]
// Make bid request for banner ad (default behaviour)
adUnit?.adFormats = [.banner]
使用属性初始化插屏广告单元
- configID - Bridgewell服务器上存储的曝光ID
- minSizePercentage - 指定广告可能占据设备实际大小百分比的最小宽度和高度。
注意: minSizePercentage - 在横幅广告的竞标过程中起着重要作用。如果提供的空间不足,合作伙伴不会响应投标。
调用 loadAd() 方法,它会向Bridgewell服务器发送投标请求。
等待广告加载完毕,并在合适的时间将其展示给用户。
// MARK: InterstitialRenderingAdUnitDelegate
func interstitialDidReceiveAd(_ interstitial: InterstitialRenderingAdUnit) {
// Now the ad is ready for display
}
集成示例:
// 1. Create an Ad Unit
rewardedAd = RewardedAdUnit(configID: CONFIG_ID)
rewardedAd.delegate = self
// 2. Load an Ad
rewardedAd.loadAd()
/// .......
// 3. Display the Ad
if rewardedAd.isReady {
rewardedAd.show(from: self)
}
使用参数创建RewardedAdUnit对象。
- configID - Bridgewell服务器上存储的曝光ID
调用 loadAd()
方法,它会向Bridgewell服务器发送投标请求。
等待广告加载完毕,并在合适的时间将其展示给用户。
// MARK: RewardedAdUnitDelegate
func rewardedAdDidReceiveAd(_ rewardedAd: RewardedAdUnit) {
// Now the ad is ready for display
}
版权所有 © 2024 Bridgewell