Rewarded Video Integration for iOS (Chinese)

 在开始之前确保您已在您的应用中正确集成 ironSource SDK 及其他任何所需广告网络适配器。集成概述在此

第 1 步. 实现激励视频Delegate

ironSource SDK 会在广告可用及完成时触发多个事件通知您,以便您知道何时奖励用户。 SDK 将就下列所有可能事件通知您的delegate:

OBJECTIVE-C

#pragma mark - ISRewardedVideoDelegate
//Called after a rewarded video has changed its availability.
//@param available The new rewarded video availability. YES if available //and ready to be shown, NO otherwise.
- (void)rewardedVideoHasChangedAvailability:(BOOL)available {
}
//Called after a rewarded video has been viewed completely and the user is //eligible for reward.@param placementInfo An object that contains the //placement's reward name and amount.
- (void)didReceiveRewardForPlacement:(ISPlacementInfo *)placementInfo {
}
//Called after a rewarded video has attempted to show but failed.
//@param error The reason for the error
- (void)rewardedVideoDidFailToShowWithError:(NSError *)error {
}
//Called after a rewarded video has been opened.
- (void)rewardedVideoDidOpen {
}
//Called after a rewarded video has been dismissed.
- (void)rewardedVideoDidClose {
}
//Note: the events below are not available for all supported rewarded video ad networks. Check which events are available per ad network you choose //to include in your build.
//We recommend only using events which register to ALL ad networks you //include in your build.
 //Called after a rewarded video has started playing.
- (void)rewardedVideoDidStart {
}
//Called after a rewarded video has finished playing.
- (void)rewardedVideoDidEnd {
}

SWIFT

//MARK: ISRewardedVideoDelegate Functions
    /**
     Called after a rewarded video has changed its availability.
     
     @param available The new rewarded video availability. YES if available and ready to be shown, NO otherwise.
     */
    public func rewardedVideoHasChangedAvailability(_ available: Bool) {
   }
    
    /**
     Called after a rewarded video has finished playing.
     */
    public func rewardedVideoDidEnd() {
    }
    
    /**
     Called after a rewarded video has started playing.
     */
    public func rewardedVideoDidStart() {
   }
    
    /**
     Called after a rewarded video has been dismissed.
     */
    public func rewardedVideoDidClose() {
   }
    
    /**
     Called after a rewarded video has been opened.
     */
    public func rewardedVideoDidOpen() {
   }
    
    /**
     Called after a rewarded video has attempted to show but failed.
     
     @param error The reason for the error
     */
    public func rewardedVideoDidFailToShowWithError(_ error: Error!) {
   }
    
    /**
     Called after a rewarded video has been viewed completely and the user is eligible for reward.
     
     @param placementInfo An object that contains the placement's reward name and amount.
     */
    public func didReceiveReward(forPlacement placementInfo: ISPlacementInfo!) {
   }

Note:  注意
  • ironSource 提供错误码机制,以便您了解集成或产品运行中发生的错误。请在此处参见完整向导。
  •  请勿假定回调总是运行在主线程中。任何 UI 交互或 ironSource 产生的回调结果更新都需要在执行前传给主线程。

第 2 步. 向您的用户显示视频广告

通过正确实现激励视频委托及其函数,您即可通过  rewardedVideoHasChangedAvailability 接收可用状态。 当广告可用状态改变时,下列委托函数将会通知您:

OBJECTIVE-C

/**
*Called after a rewarded video has changed its availability.
*@param available The new rewarded video availability. YES if available *and *ready to be shown, NO otherwise.
*/
(void)rewardedVideoHasChangedAvailability:(BOOL)available {
}

SWIFT

 /**
     Called after a rewarded video has changed its availability.
     @param available The new rewarded video availability. YES if available and ready to be shown, NO otherwise.
     */
    public func rewardedVideoHasChangedAvailability(_ available: Bool) {
   }

或者,按以下方式直接调用请求广告可用状态:

OBJECTIVE-C

[IronSource hasRewardedVideo];

SWIFT

IronSource.hasRewardedVideo()

一旦广告网络有可用视频时,您即已准备好向用户展示此视频广告。此时是插入触发器以鼓励用户观看视频广告的理想时机。 调用下列方法向用户展示视频广告:

OBJECTIVE-C

[IronSource showRewardedVideoWithViewController:(UIViewController *)viewController placement:(nullable NSString *)placementName];

SWIFT

IronSource.showRewardedVideo(with: <UIViewController>, placement: <String?>)

Note: 注意:当 placementName 参数为 null 时,SDK 将从 ironSource 平台接收默认展示位置设定配置。

利用 ironSource 广告位置布置工具,您可自定义优化激励视频体验。此工具使您可以依奖励不同而从不同位置向用户展示视频。您可使用以下函数,定义您希望展示广告的确切位置。请前往广告展示位置文档以了解更多细节信息。 要获取关于每个广告展示位置的具体奖励详情,您可调用以下代码:

OBJECTIVE-C

[IronSource rewardedVideoPlacementInfo:(NSString *)placementName];
if(pInfo != NULL)
{
	 NSString * rewardName = [pInfo rewardName];
	 NSNumber * rewardAmount = [pInfo rewardAmount];
}

SWIFT

let placementInfo = IronSource.rewardedVideoPlacementInfo(<;placementName: String>)
        if  placementInfo != nil {
            let rewardName = placementInfo.placementName
            let rewardAmount = placementInfo.rewardAmount
        }

除 ironSource 广告展示位置外,您现在可为所选展示位置广告配置频次和花费预算节奏设置。频次和花费预算节奏可通过限制在给定时间内的总广告投放数来提升应用的用户体验。请在此处了解更多关于频次和花费预算节奏的信息。

Note: 注意:若您选择为激励视频使用频次和花费预算节奏工具,我们推荐调用以下方法以判定指定展示位置是否已到达其广告限值。这样做可确保当展示位置已达到限值后,不会出现 “激励视频” 按钮,进而也就不会投放广告。

OBJECTIVE-C

[IronSource isRewardedVideoCappedForPlacement:@"Placement"];

SWIFT

IronSource.isRewardedVideoCapped(forPlacement: <String>)

全新!动态 UserID 验证 AdRewarded Transactions 动态 UserID 是在会话中可更改的参数,其可在服务器至服务器广告奖励回调中接收。此参数可帮助验证 AdRewarded transactions ,且其必须在调用 ShowRV 前设置。

OBJECTIVE-C

[IronSource setDynamicUserId:@"DynamicUserId"];

SWIFT

IronSource.setDynamicUserId(<dynamicUserId: String>)

第 3 步. 奖励用户

ironSource SDK 将在用户每次成功完成一条视频时触发 didReceiveReward 事件。在奖励前,您将会通过以下deldgate函数获得通知。

Note: 注意: didReceiveReward rewardedVideoDidClose 事件是异步的。请确保设置好监听器以在 rewardedVideoDidClose 事件之后触发 didReceiveReward ,监听奖励事件。\

展示位置对象同时包括了您在 ironSource 管理员中定义的奖励名称 & 奖励总额

OBJECTIVE-C

//Called after a rewarded video has been viewed completely and the user is //eligible for reward.
//@param placementInfo is an object that contains the placement's reward //name and amount.
- (void)didReceiveRewardForPlacement:(ISPlacementInfo *)placementInfo {
    	 NSNumber *rewardAmount = [placementInfo rewardAmount];
	 NSString *rewardName = [placementInfo rewardName];
}

SWIFT

/**
     Called after a rewarded video has been viewed completely and the user is eligible for reward. @param placementInfo An object that contains the placement's reward name and amount.
*/
  public func didReceiveReward(forPlacement placementInfo: ISPlacementInfo!) {
    }

Note: 注意
  1. 您 ironSource 账户的默认设置将通过  didReceiveReward  回调来通知您用户的完成情况/奖励。此外,若您希望在后台服务器中接收通知,您可以开启服务器至服务器回调。
  2. 若您启用服务器至服务器回调,请牢记不要为同一次视频播放完成而奖励用户多次。我们将同时触发客户端回调和服务器至服务器的回调,所以每次完成您会收到两次通知。要使用服务器至服务器回调,请参见此处

  完成! 您现在已在应用中设置好投放激励视频。

首次集成小技巧  若您是第一次对您的应用进行集成,则您的应用在 ironSource 控制台中默认处于 ‘测试模式‘。当应用处于测试模式时, ironSource SDK 将向控制台打印更多日志,以便提供更多 SDK 处理细节。要测试您的广告资源,请设置您的测试设备。在您开启真实广告资源前,您只会收到测试广告,并且不会因此获利。当您的应用准备好投放真实广告资源时,请确保在广告单元页面选择 Go Live! 

ironsource-go-live-with-rewarded-video