所谓激励广告,就是用户与之进行互动从而获取应用内奖励的一种广告。本指南将介绍如何将 Adx3 激励广告接入到 iOS 应用中
前提条件
务必使用测试广告进行测试
在构建和测试应用时,请确保使用的是测试广告,而不是实际投放的广告。否则,可能会导致您的账号被暂停使用。对于 iOS 激励广告,使用下面的测试专用广告单元 ID:
该测试广告单元 ID 已经过专门配置,可确保每个请求返回的都是测试广告。您可以在自己应用的编码、测试和调试过程中随意使用该测试广告单元 ID。需要注意的一点是,请务必在发布应用前用您的广告单元 ID 替换该测试广告单元 ID。
接入步骤
请求广告
请求激励广告通过 [Adx3RewardAd sharedManager] 中 loadAdWithPlacementID: 方法完成,loadAdWithPlacementID: 方法需要您的广告单元 ID,userId 可不传或者传入您的应用为用户设置的 userId,代码示例:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
loadRewardAd()
// Do any additional setup after loading the view.
}
func loadRewardAd() {
Adx3RewardAd.sharedManager().load(withPlacementID: "Your Placement ID", userId: "", delegate: self)
}
}
#import "Adx3Framework/Adx3Ad.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self loadRewardAd];
}
- (void)loadRewardAd {
[[Adx3RewardAd sharedManager] loadAdWithPlacementID:@"Your Placement ID" userId:@"" delegate:self];
}
@end
注册回调
您可以通过实现 Adx3RewardDelegate 中的相关方法(全部可选),监听请求结果和处理广告的相关事件。代码示例:
import UIKit
class ViewController: UIViewController, Adx3RewardDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}
extension ViewController {
func didFinishLoadingAD(withPlacementID placementID: String!) {
print("----Interstitial AD Load Finish----")
}
func didFailToLoadAD(withPlacementID placementID: String!, error: Error!) {
print("----\(error.debugDescription)----")
}
func rewardDidShow(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
}
func rewardDidClick(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
}
func rewardDidClose(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
}
func rewardDidEndPlayingVideo(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
}
func rewardDidStartPlayingVideo(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
}
func rewardFailedToShow(forPlacementID placementID: String!, error: Error!, extra: [AnyHashable : Any]!) {
}
func rewardDidFailToPlayVideo(forPlacementID placementID: String!, error: Error!, extra: [AnyHashable : Any]!) {
}
}
#import "Adx3Framework/Adx3Ad.h"
@interface ViewController () <Adx3RewardDelegate>
@end
@implementation ViewController
-(void)didFinishLoadingADWithPlacementID:(NSString *)placementID {
NSLog(@"----Reward AD Load Finish----");
}
-(void)didFailToLoadADWithPlacementID:(NSString*)placementID error:(NSError*)error {
NSLog(@"----%@----",error.description);
}
-(void)rewardDidShowForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {
}
-(void)rewardFailedToShowForPlacementID:(NSString*)placementID error:(NSError*)error extra:(NSDictionary*)extra {
}
-(void)rewardDidStartPlayingVideoForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {
}
-(void)rewardDidEndPlayingVideoForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {
}
-(void)rewardDidFailToPlayVideoForPlacementID:(NSString*)placementID error:(NSError*)error extra:(NSDictionary*)extra {
}
-(void)rewardDidCloseForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {
}
-(void)rewardDidClickForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {
}
@end
展示广告
在向用户展示激励广告之前,您必须为用户提供明确的选项,让用户可以自行选择是否通过观看激励广告来换取奖励。激励广告始终必须是用户可以选择的一种体验。代码示例:
func showRewardAd() {
if Adx3RewardAd.sharedManager().rewardIsReady() {
Adx3RewardAd.sharedManager().showReward(in: self, delegate: self)
}
}
- (void)showRewardAd {
if ([[Adx3RewardAd sharedManager] rewardIsReady]) {
[[Adx3RewardAd sharedManager] showRewardInViewController:self delegate:self];
}
}