iOS-Integration
Table of Contents
1 iOS integration guide
1.1 Download Lighthouse rewards video SDK:
You can find our sdk demo on github.com. You can find sample integration code in the project.
1.2 Code integration with Xcode:
1.2.1 Import Lighthouse Ads:
Drag-and-drop the Framework into your project and copy it. Import lighthouse Ads and set the view controller as delegate:
#import <Adirects_SDK/Adirects_SDK.h> @interface ViewController ()<LighthouseInterstailAdDelegate>
Implement the delegate functions in ViewController implementation(.m).
/** This function will be called if it's failed to preload ads materials(e.g: video files). @param lighthouseAd @param error error @param placementId */ - (void)lighthouseAd:(LighthouseInterstailAd *)lighthouseAd didFailPreloadWithError:(NSError *)error withPlacementId:(NSString *)placementId; /** This function will be called each time one placement had been pre-loaded successfully. @param lighthouseAd @param placementId */ - (void)lighthouseAdsReady:(LighthouseInterstailAd *)lighthouseAd withPlacementId:(NSString *)placementId; /** This function will be called after ads been showed @param lighthouseAd */ - (void)lighthouseAdDidFinishShow:(LighthouseInterstailAd *)lighthouseAd; /** This function will be called if it's failed to display an ads @param lighthouseAd @param error error */ - (void)lighthouseAd:(LighthouseInterstailAd *)lighthouseAd didFailShowWithError:(NSError *)error; /** This function will be called when the ads starts loading. @param lighthouseAd */ - (void)lighthouseAdDidStartShow:(LighthouseInterstailAd *)lighthouseAd; /** This function will be called after closing ads. @param lighthouseAd */ - (void)lighthouseAdDidClickClose:(LighthouseInterstailAd *)lighthouseAd; /** This function will be called after user clicked download. @param lighthouseAd */ - (void)lighthouseAdDidClickDownload:(LighthouseInterstailAd *)lighthouseAd;
Initialize the sdk with publisher id which was generated in our publisher management platform. it needs to check the avalibility of each placement before calling to show the ads. The logic should be as following.
For example, you obtain your publisher id as "3-10004" from our publisher management platform. Firstly initialize the sdk with your publisher id. This operation might take time to download the needed materials for valid placements of the publisher. The ads materials will be cached locally. The download will be occured in another thread to avoid blocking your application loading.
@property (nonatomic, strong) LighthouseInterstailAd *lighthouseAd; - (void)viewDidLoad { [super viewDidLoad]; // placements NSArray* placementIDsArray = @[@"<Your_PlacementID_1>", @<Your_PlacementID_2>", @"<Your_PlacementID_3>"]; _lighthouseAd = [LighthouseInterstailAd initialize:@"3-10004" withPlacements:placementIDsArray delegate:self]; }
To show any valid placement Ads you need to check the avalibility of it.
// placements if ([_lighthouseAd isReady:@"yourplacementid"]) { [_lighthouseAd showWithplacementId:@"yourplacementid"]; }
1.2.2 Reward the user for watching ads:
To incent the user it's useful to reward the user after watching the video ads. Common reards could be:
- Free in-game currency;
- A performance boost for a few minutes;
- An opportunity to continue after a game over;
- In-game item or level unlocks
Developer can implement the callback function implementation in the delegation.
@param lighthouseAd */ - (void)lighthouseAdDidFinishShow:(LighthouseInterstailAd *)lighthouseAd{ //reward user }