Rewarded Video Integration for Xamarin iOS
Step 1. Implement the Rewarded Video Delegate
The ironSource SDK fires several events to inform you of your Rewarded Video activity. To receive these events, we suggest the following:
- Create a class which inherits from LevelPlayRewardedVideoDelegate. It is recommend to create a separate class for each delegate
public class RewardedVideoLevelPlayDelegate : LevelPlayRewardedVideoDelegate { readonly UIViewController viewController; public RewardedVideoLevelPlayDelegate(ViewController viewController) { this.viewController = viewController; } //Invoked when the end user clicked on the RewardedVideo ad public override void didClick(ISPlacementInfo placementInfo, ISAdInfo adInfo) { } //Invoked when the RewardedVideo ad view is about to be closed. public override void didCloseWithAdInfo(ISAdInfo adInfo) { } //Invoked when RewardedVideo call to show a rewarded video has failed public override void didFailToShowWithError(NSError error, ISAdInfo adInfo) { } //Invoked when the RewardedVideo ad view has opened. public override void didOpenWithAdInfo(ISAdInfo adInfo) { } //Invoked when the user completed the video and should be rewarded. public override void didReceiveRewardForPlacement(ISPlacementInfo placementInfo, ISAdInfo adInfo) { } //Invoked after a rewarded video has changed its availability to true. public override void hasAvailableAdWithAdInfo(ISAdInfo adInfo) { } //Invoked after a rewarded video has changed its availability to false. public override void hasNoAvailableAd() { } }
- Create and instantiate a RewardedVideoLevelPlayDelegate object. Set the delegate using the new object.
Make sure to call the setLevelPlayRewardedVideoDelegate before the SDK initialisation.
RewardedVideoLevelPlayDelegate mRewardedVideoLevelPlayDelegate; // Define the listener mRewardedVideoLevelPlayDelegate = new RewardedVideoLevelPlayDelegate(this); // Set the delegate IronSource.setLevelPlayRewardedVideoDelegate(mRewardedVideoLevelPlayDelegate);
Serve Video Ad
Once an ad network has an available video, you will be ready to show the video to your users. Before you display the ad, make sure to pause any game action, including audio, to ensure the best experience for your users.
IronSource.ShowRewardedVideoWithViewController(this);
Step 2. Set UserID
Dynamic UserID to Verify AdRewarded Transactions
The Dynamic UserID is a parameter that can be changed throughout the session and will be received in the server-to-server ad rewarded callbacks. This parameter helps verify AdRewarded transactions and must be set before calling ShowRewardedVideo.
IronSource.SetDynamicUserId(USER_ID);
Step 3. Reward the User
The ironSource Plugin will fire the didReceiveRewardForPlacement event each time the user successfully views a video. The RewardedVideoDelegate will be in place to receive this event so you can reward the user successfully.
Reward Details
The Placement object contains both the Reward Name & Reward Amount of the Placement as defined in ironSource account:
public override void didReceiveRewardForPlacement(ISPlacementInfo placementInfo, ISAdInfo adInfo) { //TODO - here you can reward the user according to the given amount string rewardName = placementInfo.RewardName; int rewardAmount = placementInfo.RewardAmount; }
Server-to-Server Callbacks
If you turn on server-to-server callbacks, remember not to reward the user more than once for the same completion. We will be firing both the client-side callback and the server-to-server callback, so you will get two notifications for each completion. To utilize server-to-server callbacks, see here.
Done!
You are now all set to deliver Rewarded Video ads in your app!