This section describes how to integrate with the AdFalcon’s iOS SDK in order to consume the services available by the network.
in order to integrate with the SDK, please perform the following steps:
Add Rewarded Video Ad to your Header and Create an instance
- Import AdFalconSDK
- Define a property from ADFRewardedVideoAd
- Create an instance of ADFRewardedVideoAd
@import AdFalconSDK; @interface RewardedVideoSampleViewController () @property ADFRewardedVideoAd * rewardedVideoAd; @end @implementation RewardedVideoSampleViewController - (void)viewDidLoad { [super viewDidLoad]; self.rewardedVideoAd = [ADFRewardedVideoAd new]; }
Implement ADFRewardedVideoAdDelegate (Optional)
- Adapt ADFRewardedVideoAdDelegate in your interface
@interface RewardedVideoSampleViewController ()<ADFRewardedVideoAdDelegate>
- Set the delegate to the object which implements the ADFRewardedVideoAdDelegate
self.rewardedVideoAd.delegate = self;
- Override the delegate’s methods; All the delegate’s methods are optional, we recommend implementing them. that will help you to track the lifecycle of the rewarded video ad. the most important delegate’s method is rewardedVideoAd:didRewardUserWithName:amount: because this method is fired when the user deserves the rewarded item after watching the video ad
/* * This Method is fired when the rewarded video ad is loaded completley */ - (void)rewardedVideoAdDidLoadAd:(ADFRewardedVideoAd*)rewardedVideoAd{ } /* * This Method is fired when the user deserves the rewarded item */ - (void)rewardedVideoAd:(ADFRewardedVideoAd*)rewardedVideoAd didRewardUserWithName:(NSString*) name amount:(NSInteger) amount{ } /* * This Method is fired when an error occurs such as No Ad, Communication Error, Invalid publisher etc. */ - (void)rewardedVideoAd:(ADFRewardedVideoAd*)rewardedVideoAd didFailToLoadAdWithErrorCode:(NSInteger)errorCode message:(NSString*) message{ } /* * This Method is fired when the rewarded video ad's screen is presented successfully. */ - (void)rewardedVideoAdDidShowAd:(ADFRewardedVideoAd*)rewardedVideoAd{ } /* * This Method is fired when the rewarded video ad's screen failed to be presented. */ - (void)rewardedVideoAd:(ADFRewardedVideoAd*)rewardedVideoAd didFailToShowAdWithError:(NSError*) error{ } /* * This Method is fired when the user clicks on close indicator and the rewarded video ad's screen is being dismissed. */ - (void)rewardedVideoAdWillCloseAd:(ADFRewardedVideoAd*)rewardedVideoAd{ } /* * This Method is fired when the rewarded video ad's screen was dismissed completley. */ - (void)rewardedVideoAdDidCloseAd:(ADFRewardedVideoAd*)rewardedVideoAd{ } /* * This Method is fired when the video ad is being played. */ - (void)rewardedVideoAdDidStartAd:(ADFRewardedVideoAd*)rewardedVideoAd{ } /* * This Method is fired when the video ad has completed successfully. */ - (void)rewardedVideoAdDidEndAd:(ADFRewardedVideoAd*)rewardedVideoAd{ } /* * This Method is fired when the user performs an action such as download app, make call, send SMS etc., * the user will leave the application. */ - (void)rewardedVideoAdWillLeaveApplication:(ADFRewardedVideoAd*)rewardedVideoAd{ }
Request Rewarded Video Ad
Request a rewarded video ad by passing your Site ID and the ADFTargetingParams
[self.rewardedVideoAd loadAdWithSiteID:@"dca7b6542cce47c6b27e78caa529c296" targetingParams:nil];
Show The Loaded Rewarded Video Ad
We recommend using [ADFRewardedVideoAd isReady] before showing the rewarded video ad, to ensure the Ad is loaded successfully and ready to be shown.
To show the loaded rewarded video ad, you should call [ADFRewardedVideoAd showWithViewController:] with the top UIViewController.
In case you pass a bottom UIViewController to this method, the Rewarded video ad will not be able to be presented and the iOS will raise an exception.
if(self.rewardedVideoAd != nil && [self.rewardedVideoAd isReady]){ [self.rewardedVideoAd showWithViewController:self]; }
Full Example
#import "RewardedVideoSampleViewController.h" @import AdFalconSDK; @interface RewardedVideoSampleViewController ()<ADFRewardedVideoAdDelegate> @property ADFRewardedVideoAd * rewardedVideoAd; @end @implementation RewardedVideoSampleViewController - (void)viewDidLoad { [super viewDidLoad]; [self loadRewardedVideoAd]; } - (void) loadRewardedVideoAd { //Create ADFRewardedVideoAd self.rewardedVideoAd = [ADFRewardedVideoAd new]; //To track the lifecycle events, set the delegate to the object which implements the ADFRewardedVideoAdDelegate self.rewardedVideoAd.delegate = self; //Request a rewarded video ad by passing your SiteID and the targeting parameters [self.rewardedVideoAd loadAdWithSiteID:@"dca7b6542cce47c6b27e78caa529c296" targetingParams:nil]; } - (void) showRewardedVideoAd { //We recommend using [ADFRewardedVideoAd isReady] before presenting the rewarded video ad, to ensure the Ad is loaded successfully and ready to be shown. if(self.rewardedVideoAd != nil && [self.rewardedVideoAd isReady]){ //Show the Rewarded video ad from the top UIViewController [self.rewardedVideoAd showWithViewController:self]; } } #pragma -mark ADFRewardedVideoAdDelegate /* * This Method is fired when the rewarded video ad is loaded completley */ - (void)rewardedVideoAdDidLoadAd:(ADFRewardedVideoAd*)rewardedVideoAd { [self showRewardedVideoAd]; } /* * This Method is fired when the user deserves the rewarded item */ - (void)rewardedVideoAd:(ADFRewardedVideoAd*)rewardedVideoAd didRewardUserWithName:(NSString*) name amount:(NSInteger) amount{ } /* * This Method is fired when an error occurs such as No Ad, Communication Error, Invalid publisher etc. */ - (void)rewardedVideoAd:(ADFRewardedVideoAd*)rewardedVideoAd didFailToLoadAdWithErrorCode:(NSInteger)errorCode message:(NSString*) message{ } /* * This Method is fired when the rewarded video ad's screen is presented successfully. */ - (void)rewardedVideoAdDidShowAd:(ADFRewardedVideoAd*)rewardedVideoAd{ } /* * This Method is fired when the rewarded video ad's screen failed to be presented. */ - (void)rewardedVideoAd:(ADFRewardedVideoAd*)rewardedVideoAd didFailToShowAdWithError:(NSError*) error{ } /* * This Method is fired when the user clicks on close indicator and the rewarded video ad's screen is being dismissed. */ - (void)rewardedVideoAdWillCloseAd:(ADFRewardedVideoAd*)rewardedVideoAd{ } /* * This Method is fired when the rewarded video ad's screen was dismissed completley. */ - (void)rewardedVideoAdDidCloseAd:(ADFRewardedVideoAd*)rewardedVideoAd{ } /* * This Method is fired when the video ad is being played. */ - (void)rewardedVideoAdDidStartAd:(ADFRewardedVideoAd*)rewardedVideoAd{ } /* * This Method is fired when the video ad has completed successfully. */ - (void)rewardedVideoAdDidEndAd:(ADFRewardedVideoAd*)rewardedVideoAd{ } /* * This Method is fired when the user performs an action such as download app, make call, send SMS etc., * the user will leave the application. */ - (void)rewardedVideoAdWillLeaveApplication:(ADFRewardedVideoAd*)rewardedVideoAd{ } @end