MaaS Advertising iOS SDK
版本 4.0.0
概览
这是 Phunware 的 MaaS 广告模块的 iOS SDK。访问 https://ssp-portal.phunware.com 获取更多详细信息并注册。
要求
- iOS 10.1 或更高版本
- Xcode 8.1 或更高版本
- Swift 4.1 或 4.2
安装
CocoaPods
Phunware 建议使用 CocoaPods 集成框架。要使用 CocoaPods 将 PWAds 集成到 Xcode 项目中,请在您的 Podfile
中指定它
pod 'PWAds'
使用说明
横幅广告
从 Phunware 广告服务器返回横幅广告后将立即显示。
响应函数包含在传递给放置请求的闭包中。
创建横幅
- PWBanner(placement, parentViewController, position)
- placement (目前,Phunware 应返回一个放置,但将来可能返回列表。目前,只使用 placement[0]。
- parentViewController (这是包含横幅的包含控制器。通常这是执行横幅请求的视图控制器)
- position (一个表示横幅应在屏幕上出现的位置的字符串常量。位置值可以在 Phunware.MRAIDConstants 中找到)
检索横幅
宽度和高度是可选的。大多数时间,宽度和高度将来自您的 Phunware 配置中的区域,但如果未设置,则可能要在此处设置回退。
let config = PlacementRequestConfig(accountId: <accountId>, zoneId: <zoneId>, width:320, height:50, customExtras:nil)
Phunware.requestPlacement(with: config) { response in
switch response {
case .success(_ , let placements):
guard placements.count == 1 else {
// error
return
}
guard placements[0].isValid else {
// error
return
}
self.banner = PWBanner(placement:placements[0], parentViewController:self, position:Positions.BOTTOM_CENTER)
case .badRequest(let statusCode, let responseBody):
return
case .invalidJson(let responseBody):
return
case .requestError(let error):
return
}
}
横幅广告
您的视图控制器需要实现 PWInterstitialDelegate 接口以检索事件信息。
这些方法包括
func interstitialReady(_ interstitial: PWInterstitial) {
print("ready");
}
func interstitialFailedToLoad(_ interstitial: PWInterstitial) {
print("failed");
}
func interstitialClosed(_ interstitial: PWInterstitial) {
print("close");
}
func interstitialStartLoad(_ interstitial: PWInterstitial) {
print("start load");
}
检索横幅广告
let config = PlacementRequestConfig(accountId: <accountId>, zoneId: <zoneId>, width:nil, height:nil, customExtras:nil)
Phunware.requestPlacement(with: config) { response in
switch response {
case .success(_ , let placements):
guard placements.count == 1 else {
return // interstitials should currently only return a single ad
}
guard placements[0].isValid else {
return
}
if(placements[0].body != nil && placements[0].body != ""){
self.interstitial = PWInterstitial(placement:placements[0], parentViewController:self, delegate:self, respectSafeAreaLayoutGuide:true)
}
default:
return
}
}
创建横幅广告
- PWInterstitial(placement, parentViewController, delegate, respectSafeAreaLayoutGuide)
- placement (与横幅类似,目前 Phunware 将返回一个放置。)
- parentViewController (将包含横幅的视图控制器,通常是获取横幅放置的相同控制器)
- delegate (实现 PWInterstitialDelegate 接口的类。通常是获取横幅的视图控制器)
- respectSafeAreaLayoutGuide (某些应用程序可能选择使用其布局考虑安全区域布局指南,以便显示状态栏。如果您的应用程序这样做,则此设置将告诉横幅这样做)
一旦检索到,将调用interstitialReady函数。此后,您可以在任何时间使用以下方式显示插页广告:
interstitial.display()
插页广告只能显示一次,之后您必须检索另一个。
示例
要使用附带的示例,请导航到Terminal中的Samples/Sample目录并执行pod update
命令。安装完成后,在Xcode中打开Sample.xcworkspace
。
隐私
您理解并同意Phunware的隐私政策,该政策位于http://www.phunware.com/privacy
。如果Phunware的软件使用需要您自己的隐私政策,您还同意将Phunware的隐私政策条款包含在您的隐私政策中,提供给您的最终用户。
条款
使用此软件需要审查和接受位于http://www.phunware.com/terms/
的我们针对开发者使用的条款和条件。