Rewarded and Fullscreen Video

Appnext iOS SDK - Rewarded and Fullscreen video ad unit

Ad Unit Integration

Make sure to complete the Getting Started with the iOS SDK steps before you begin

Step 1: Add import statement

Add the following import statement in your pre-compiled header or in your .m/.h file where you intend to instantiate and use the Appnext SDK. If your application is written in swift add it to your bridging-header.

#import <AppnextLib/AppnextLib.h>

Step 2: Define a new Ad

Make sure to set your app's placementID before loading the ad.

FullScreen:

AppnextFullScreenVideoAd *fullScreen = [[AppnextFullScreenVideoAd alloc] initWithPlacementID:placementID];

Rewarded:

AppnextRewardedVideoAd *rewarded = [[AppnextRewardedVideoAd alloc] initWithPlacementID:placementID];

Step 3: Loading an Ad

You must load Fullscreen and Rewarded Ads before showing them. In case the loadAd function was not called, the SDK will return an error - "Ad not ready".

Fullscreen:

[fullScreen loadAd];

Rewarded:

[rewarded loadAd];

❗️

Notes:

  • You must load the ad before showing it. In case the loadAd function was not called, the SDK will return an error - "ad not ready"
  • It may take time for an ad to load and be ready to show, depending on the user's internet speed. It is highly recommended to load the ad as soon as possible during the app life-cycle

Step 5: Showing the Ad

Fullscreen

if (self.fullScreen.adIsLoaded)
{
    [self.fullScreen showAd];
} else
{
    // continue...
}

Rewarded

if (self.rewarded.adIsLoaded)
{
    [self.rewarded showAd];
} else
{
    // continue... 
}

Step 6 (optional): Delegates

In order to receive client-side callbacks, the client can set a delegate for each Ad:

//Fullscreen:
fullScreen.delegate = self;

//Rewarded:
rewarded.delegate = self;

For Fullscreen and Rewarded Ads the delegate need to conform to:

@protocol AppnextVideoAdDelegate <AppnextAdDelegate>
@optional
- (void) videoEnded:(AppnextAd *)ad;
@end
@protocol AppnextAdDelegate <NSObject>
@optional
- (void) adLoaded:(AppnextAd *)ad;
- (void) adOpened:(AppnextAd *)ad;
- (void) adClosed:(AppnextAd *)ad;
- (void) adClicked:(AppnextAd *)ad;
- (void) adUserWillLeaveApplication:(AppnextAd *)ad;
- (void) adError:(AppnextAd *)ad error:(NSString *)error;
@end

Possible errors returned to client in AppnextAdDelegate method adError:error:

static NSString * const kAdErrorNoInternetConnection = @"No internet connection";
static NSString * const kAdErrorNoPlacementID = @"Placement ID cannot be empty";
static NSString * const kAdErrorDownloadingResources = @"Error Downloading Resources";
static NSString * const kAdErrorAdNotReady = @"Ad not ready";
static NSString * const kAdErrorPreparingViews = @"Error Preparing Views";
static NSString * const kAdErrorLoadingAd = @"Error Loading Ad";
static NSString * const kAdErrorBadParameters = @"Bad parameters";
static NSString * const kAdErrorEmptyResponse = @"Empty response";
static NSString * const kAdErrorNoAds = @"No ads";
static NSString * const kAdErrorFailedLoadingAds = @"Failed loading ads";
static NSString * const kAdErrorNoSuitableAd = @"No suitable ad";
static NSString * const kAdErrorVideoFileNameNotValid = @"Video file name not valid";

Configuring the ad unit

Custom Configuration

By default, the SDK configuration will be loaded from Appnext's server. You can change the configuration directly by config or through the setter function.

Using Config

Change to each configuration (Fullscreen / Rewarded) should be made separately.
In order to use custom configuration, import the following class:

//Fullscreen configuration instance:
AppnextFullScreenVideoAdConfiguration *fullScreenConfig = [[AppnextFullScreenVideoAdConfiguration alloc] init];

//Rewarded configuration instance:
AppnextRewardedVideoAdConfiguration *rewardedConfig = [[AppnextRewardedVideoAdConfiguration alloc] init];

Examples:

Fullscreen config example:

AppnextFullScreenVideoAdConfiguration *config = [[AppnextFullScreenVideoAdConfiguration alloc] init];
[config setButtonText:@"Install"];
[config setButtonColor:@"#ffffff"];
[config setCategories:@"category1,category2"];
[config setPostback:@"postback"];
[config setProgressType:ANProgressTypeClock];
[config setProgressColor:@"#ffffff"];
[config setVideoLength:ANVideoLengthDefault];
[config setMute:NO];
[config setPreferredOrientation:kPreferredOrientationTypeStringAutomatic];
[config setClickInApp:YES];

// You can alternatively set the property directly:

//config.buttonText = @"Install";
//config.buttonColor = @"#ffffff";
//config.categories = @"category1,category2";
//config.postback = @"postback";
//config.progressType = ANProgressTypeClock;
//config.progressColor = @"#ffffff";
//config.showClose = YES;
//config.videoLength = ANVideoLengthDefault;
//config.mute = NO;
//config.preferredOrientation = kPreferredOrientationTypeStringAutomatic;
//config.clickInApp = YES;
AppnextFullScreenVideoAd *fullScreen = [[AppnextFullScreenVideoAd alloc] initWithConfig:config placementID:placementID];
fullScreen.delegate = self;

//You can also set the property after the ad is created on the ad itself:

//[fullScreen setButtonText:@"Install"];
//[fullScreen setButtonColor:@"#ffffff"];
//[fullScreen setCategories:@"category1,category2"];
//[fullScreen setPostback:@"postback"];
//[fullScreen setProgressType:ANProgressTypeClock];
//[fullScreen setProgressColor:@"#ffffff"];
//[fullScreen setVideoLength:ANVideoLengthDefault];
//[fullScreen setMute:NO];
//[fullScreen setPreferredOrientation:kPreferredOrientationTypeStringAutomatic];
//[fullscreen setClickInApp:YES];

Rewarded config example:

AppnextRewardedVideoAdConfiguration *config = [[AppnextRewardedVideoAdConfiguration alloc] init];
[config setButtonText:@"Install"];
[config setButtonColor:@"#ffffff"];
[config setCategories:@"category1,category2"];
[config setPostback:@"postback"];
[config setProgressType:ANProgressTypeClock];
[config setProgressColor:@"#ffffff"];
[config setVideoLength:ANVideoLengthDefault];
[config setMute:NO];
[config setPreferredOrientation:kPreferredOrientationTypeStringAutomatic];
[config setClickInApp:YES];

//You can alternatively set the property directly:

//config.buttonText = @"Install";
//config.buttonColor = @"#ffffff";
//config.categories = @"category1,category2";
//config.postback = @"postback";
//config.progressType = ANProgressTypeClock;
//config.progressColor = @"#ffffff";
//config.videoLength = ANVideoLengthDefault;
//config.mute = NO;
//config.preferredOrientation = kPreferredOrientationTypeStringAutomatic;
//config.clickInApp = YES;
AppnextRewardedVideoAd *rewarded = [[AppnextRewardedVideoAd alloc] initWithConfig:config placementID:placementID];
rewarded.delegate = self;

// You can also set the property after the ad is created on the ad itself:

//[rewarded setButtonText:@"Install"];
//[rewarded setButtonColor:@"#ffffff"];
//[rewarded setCategories:@"category1,category2"];
//[rewarded setPostback:@"postback"];
//[rewarded setProgressType:ANProgressTypeClock];
//[rewarded setProgressColor:@"#ffffff"];
//[rewarded setVideoLength:ANVideoLengthDefault];
//[rewarded setMute:NO];
//[rewarded setPreferredOrientation:kPreferredOrientationTypeStringAutomatic];
//[rewarded setClickInApp:YES];

List of configurable options

Button Text:
The install button's text (default is "Install")

Button Color:
The install button's color - a 6 hex chars starting with # (default is "#6AB344")

Category:
Set preferred ad categories

Click in-app
Determines the App Store loading method, when set to "YES" - the App Store will open "in-app" within the running app, Otherwise the App Store will open outside the running app

Install Postback:
Postback parmeters that will be posted to your server after user installed an app (make sure to encode the values)

Mute Video:
Mute the video which is played in the ad (default value is "NO")

  • YES
  • NO

Progress Type:
Choose progress type, or hide it (default is ANProgressTypeClock)

  • ANProgressTypeDefault
  • ANProgressTypeClock
  • ANProgressTypeBar
  • ANProgressTypeNone

Progress Color:

Set progress bar / clock color. 6 characters hex starting with # (default is #ffffff)

Show Close Button:

Display or hide the "x" (close) button

  • YES
  • NO

Video Length:

Set video length - 15 or 30 seconds long (default is ANVideoLengthDefault)

  • ANVideoLengthDefault - Up to 15 seconds long videos
  • ANVideoLengthShort - 20-60 seconds long videos
  • ANVideoLengthLong - Appnext's algorithm priority. Any available video campaign will be served

Please note that if no SHORT type length videos are available, long videos will be served.

Preferred Orientation:

Set the preferred orientation if both landscape and portrait are supported by the application (default is kPreferredOrientationTypeStringAutomatic)

  • kPreferredOrientationTypeStringAutomatic = @"automatic"
  • kPreferredOrientationTypeStringLandscape = @"landscape"
  • kPreferredOrientationTypeStringPortrait = @"portrait"
  • kPreferredOrientationTypeStringNotSet = @"not_set"

Server-side postback - Rewarded Video Ad

You can choose to receive server-side postbacks whenever a user finishes watching a video ("video ended" event). The "video ended" event will serve as a trigger for the reward action.

Please note that in addition to configuring the postback in this integration process, you will also need to set your postback URL on the Appnext Self-Service platform (under the "Apps" page / app "Settings & Placements" / "Advanced Settings').

In order to receive the server-side postback parameters on the "video ended" event, call the following functions before showing the ad:

AppnextRewardedServerSidePostbackParams *serverPostbackParams = [[AppnextRewardedServerSidePostbackParams alloc] init];
//Transaction ID - make sure to set a unique transaction ID per ad view
serverPostbackParams.rewardsTransactionId = @"TransactionId";

//User ID - pass the User ID so you will know which user to reward
serverPostbackParams.rewardsUserId = @"UserId";

//Currency Type - type of reward (life / credit / points)
serverPostbackParams.rewardsRewardTypeCurrency = @"TypeCurrency";

//Amount - the amount of currency that was rewarded
serverPostbackParams.rewardsAmountRewarded = @"Amount";

//Custom Parameters - pass any custom value / data
serverPostbackParams.rewardsCustomParameter = @"CustomParameter";

[rewarded setRewardedServerSidePostbackParams:serverPostbackParams];

// You can also set the params directly on the ad:

//[rewarded setRewardsTransactionId:@"TransactionId"];
//[rewarded setRewardsUserId:@"UserId"];
//[rewarded setRewardsRewardTypeCurrency:@"TypeCurrency"];
//[rewarded setRewardsAmountRewarded:@"Amount"];
//[rewarded setRewardsCustomParameter:@"CustomParameter"];
  • Make sure to encode all values passed in each function.
  • Passing value, for at least one parameter, is mandatory, for the server-side reward postback to be sent.

Example Project

Please see example project AppnextNewNativeLibSDKTest inside the SDK zip file here.

App Categories

1. Action
2. Adventure
3. Arcade
4. Board
5. Books
6. Business
7. Card
8. Casino
9. Catalogs
10. Dice
11. Education
12. Educational
13. Entertainment
14. Family
15. Finance
16. Food & Drink
17. Graphics & Design
18. Health & Fitness
19. Kids
20. Lifestyle
21. Medical
22. Music
23. Navigation
24. News
25. Photo & Video
26. Productivity
27. Puzzle
28. Racing
29. Reference
30. Role Playing
31. Simulation
32. Social Networking
33. Sports
34. Strategy
35. Travel
36. Trivia
37. Utilities
38. Weather

Make sure to encode (%20) categories with more than 1 word, example: Travel%20%26%20Local

Integration Support

Should you have any problems integrating the product, log a ticket with us by emailing [email protected]