Rewarded Video Integration for Xamarin iOS

Before You Start

Make sure you have correctly integrated the ironSource Plugin into your application. Integration is outlined here.

Step 1. Implement the Rewarded Video Delegate

First, create an additional RewardedVideoDelegate class to listen to all the ironSource Rewarded Video delegate events:

public class RewardedVideoDelegate : ISRewardedVideoDelegate
    {
       readonly UIViewController parent;
       public RVDelegate(UIViewController parent)
       {
            this.parent = parent;
       }
      /*
       * Invoked when the user completed the video and should be rewarded.
       * If using server-to-server callbacks you may ignore this delegate and wait 
       * for the callback from the ironSource server.
       * @param - placementInfo - the Placement the user completed a video from.
       */
       public override void DidReceiveRewardForPlacement(ISPlacementInfo placementInfo)
       {
       }
      /*
       * Invoked when the RewardedVideo ad view is about to be closed.
       */
       public override void RewardedVideoDidClose()
       {
       }
       /* Invoked when the video ad finishes plating. */
       public override void RewardedVideoDidEnd()
       {
       }
       /* Invoked when RewardedVideo call to show a rewarded video has failed
        * IronSourceError contains the reason for the failure.
        */
       public override void RewardedVideoDidFailToShowWithError(NSError error)
       {
       }
       /*
        * Invoked when the RewardedVideo ad view has opened.
        * Please avoid performing heavy tasks till the video ad will be closed.
        */
       public override void RewardedVideoDidOpen()
       {
       }
       /*
       * 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.
       * Invoked when the video ad starts playing.
       */
       public override void RewardedVideoDidStart()
       {
       }
      /*
       * Invoked when there is a change in the ad availability status.
       * @param - available - value will change to true when rewarded videos are 
       * available.
       * You can then show the video by calling showRewardedVideo().
       * Value will change to false when no videos are available.
       */
       public override void RewardedVideoHasChangedAvailability(bool available)
       {
       }
       /* Invoked when the end user clicked on the RewardedVideo ad */
       public override void DidClickRewardedVideo(ISPlacementInfo placementInfo)
       {
       }
    }

Next, create an instance of the RewardedVideoDelegate class you just created and pass your ViewController to the constructor as follows:

RewardedVideoDelegate rewardedVideoDelegate = new RewardedVideoDelegate(this);

Then, pass the created instance, rewardedVideoDelegate, to the SetRewardedVideoDelegate method:

IronSource.SetRewardedVideoDelegate(rewardedVideoDelegate);

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.

 Note: The DidReceiveRewardForPlacement and RewardedVideoDidClose events are asynchronous. Make sure to set up your listener to grant rewards even in cases where DidReceiveRewardForPlacement is fired after the RewardedVideoDidClose event.

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)
{
    //TODO - here you can reward the user according to the given amount
    string rewardName =  placementInfo.RewardName;
    int rewardAmount = placementInfo.RewardAmount;
}
Note:

  1. The default setting in your ironSource account is to notify you of user completions/rewards via the AdRewarded:amount callback within the client of your app. Additionally, if you would also like to receive notifications to your back-end server, you can turn on server-to-server callbacks. 

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!