Adyo iOS SDK
Adyo iOS SDK 使将 Adyo 广告集成到您的 iOS 应用变得简单。我们提供了预构建的 UI 元素,可以轻松提供广告。我们还公开了我们的 API,为您提供更多对服务体验的控制。
要求
- iOS 9 及以上
- XCode 9 及以上
安装
可以通过手动构建并将框架复制到您的项目中或通过 CocoaPods 自动完成安装。
CocoaPods
- 在您的 Podfile 中添加以下代码:
pod 'Adyo', '~> 1.6.4'
- 运行
pod install
并打开生成的 Xcode 工作空间。
用法
包含
简单导入Adyo开始
@import Adyo; // If using framework
// or
#import "Adyo.h"
创建一个AYZoneView
Adyo iOS 为您提供了一个处理广告请求、广告展示和自动刷新的AYZoneView
。可以通过程序方式或界面构建器来构建一个AYZoneView
。
方法 1:界面构建器
可以通过在Storyboard或xib文件中使用普通的UIView
对象,并指定其类为AYZoneView
,来向故事板或xib文件中添加一个AYZoneView
。请记住将视图的宽度和高度约束设置为您区域的大小。
方法 2:程序地
以程序方式创建一个AYZoneView
就像实例化一个普通的UIView
一样简单
@import Adyo;
AYZoneView *zoneView = [[AYZoneView alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];
// .. Configuration omitted
[self.view addSubview:zoneView];
配置
为了使AYZoneView
能够请求广告位,需要一个AYPlacementRequestParams
对象
// Multiple constructors are available
AYPlacementRequestParams *params = [[AYPlacementRequestParams alloc] initWithNetworkId:1 zoneId:1 userId:@"user234-11" keywords:@[@"keyword1", @"keyword2", @"keyword3"]];
// or without constructor
AYPlacementRequestParams *params = [AYPlacementRequestParams alloc] init];
params.networkId = 1;
params.zoneId = 1;
params.userId = @"user234-11";
params.keywords = @["keyword1", @"keyword2", @"keyword3"];
以下属性可用
参数 | 必需/可选 | 描述 |
---|---|---|
networkId |
必需 | 您获得的Adyo网络ID |
zoneId |
必需 | 您希望请求投放位置的区域ID。 |
userId |
可选 | 用户的唯一标识符。用于频率限制。如果没有提供 userId ,SDK将自动使用ASIdentifierManager (更多信息)来请求标识符。如果用户选择了有限的广告追踪,我们仅为每个广告请求创建一个唯一的标识符。 |
keywords |
可选 | 用于关键词定位的关键词数组。 |
width |
可选 | 手动宽度覆盖。下面解释。 |
height |
可选 | 手动高度覆盖。下面解释。 |
custom |
可选 | 可以在以后使用Adyo Analytics API进行查询的自定义属性字典。值可以是字符串、数字或布尔值。 |
请求位置
要指示AYZoneView
请求位置(广告),我们只需调用requestPlacement:
方法,该方法接受一个AYPlacementRequestParams
对象作为参数。
[_zoneView requestPlacement:params];
一旦请求了位置,AYZoneView
将自动显示广告。
注意:AYZoneView
将自动为您跟踪点击和展示。如需手动跟踪,请参阅下文。
横幅事件
使用AYZoneViewDelegate
,您可以监听特定事件。要注册事件
// Before requesting a placement
_zoneView.delegate = self;
以下事件方法可用
成功请求
- (void)zoneView:(AYZoneView *)zoneView didReceivePlacement:(BOOL)found placement:(Placement *)placement {
// If the request was successful but there were no placements found then 'found' will be false and 'placement' will be nil
}
请求失败
- (void)zoneView:(AYZoneView *)zoneView didFailToReceivePlacement:(NSError *)error {
// The banner view request failed (normally due to connectivity issues)
}
手动广告请求
如果您希望对应用程序内的广告显示有更多控制,您可以使用SDK手动请求位置
@import Adyo;
[Adyo requestPlacement:params success:^(BOOL found, Placement *placement) {
// Here you can use the placement details to create your own custom UI for the ad.
} failure:^(NSError *error) {
// Error normally due to connectivity issues
}];
位置
Placement
对象包含以下属性
属性 | 类型 | 描述 |
---|---|---|
impressionUrl | NSString* | 用于记录展示的像素URL。 |
clickUrl | NSString* | 点击广告时跳转的用户目标URL。 可以为空。 |
creativeType | NSString* | 此位置创意的类型。可以是 rich-media 或 image 。 |
creativeUrl | NSString* | 创意的URL。 rich-media 类型的URL指向 index.html ,图像类型的URL指向PNG、GIF或JPG格式的图像。 |
refreshAfter | NSTimeInterval | 下一次请求广告前等待的秒数。 |
thirdPartyImpressionUrl | NSString* | 第三方印象URL。 可以为空。 |
手动印象
要手动记录印象,可以在任何 Placement
对象上调用 recordImpression
方法
[placement recordImpression:^{
// Optional success block if request succeeded
} failure:^(NSError *adyoError, NSError *thirdPartyError) {
// Optional failure block. If either the Adyo or third party impression URL fails, we will end up here. Either one of the errors can be nil if one succeeded and the other didn't.
}];
注意:如果放置存在第三方印象URL,它也会被记录。
注意2:Adyo分析API自动检测重复的印象请求,因此您无需担心多次调用 recordImpression
方法(例如,当第三方印象URL请求失败并希望再次尝试时)。
自动尺寸检测和覆盖宽度和高度
Adyo中的所有区域都可以指定 width
和 height
。区域的维度用于选择请求位置时最佳尺寸的创意。这就是为什么始终需要使用与区域相同大小的 AYZoneView
对象很重要。
如果出于某种原因您需要请求不同大小的位置,可以在执行位置请求之前在 AYPlacementRequestParams
对象中设置 width
和 height
。
如果您使用的是具有影响其高度和宽度动态的布局约束的 AYZoneView
(例如,拉伸到屏幕大小),则只需将 AYZoneView
上的 determineSize
设置为 true
。在请求时刻,将使用 AYZoneView
的当前大小进行请求。
使用AYZoneView
// .. omitted creation of params
_zoneView.determineSize = YES; // Width and height will now be sent when the request is made
[_zoneView requestPlacement:params];
请求手册
AYPlacementRequestParams *params = [AYPlacementRequestParams alloc] init];
params.networkId = 1;
params.zoneId = 1;
// Manually override width and height of the zone
params.width = 150;
params.height = 150;
[_zoneView requestPlacement:params];
应用传输安全
Adyo的配送API与App Transport Security兼容(更多信息)。
示例项目
仓库中包含一个示例项目,其中展示了SDK的不同功能。样本应用程序中的networkId
和zoneId
值是有效的,可用于测试和演示。
该项目还提供了一个测试工具,您可以输入自定义参数以测试自己的广告。
反馈
如有任何反馈,请通过[email protected]联系我们或创建一个问题。您也欢迎提交任何更改或错误修复的拉取请求。