Freestar Ads Mediation OBJC iOS - freestar-archive/freestarcapital-SDK_documentation_iOS GitHub Wiki

Overview

Change Log

Freestar provides an effective ad mediation solution. The Freestar mediation method is universal auction, not the traditional waterfall. Universal auction is more sophisticated than waterfall and provides, by far, the best eCPM. This document describes how to integrate the Freestar SDK into your native iOS app quickly and easily. This repo is a fully integrated iOS sample app. Feel free to clone it, install the appropriate Cocoapods, open with Xcode and run it on a device.

Note: You can remotely toggle on/off any of the following ad providers as you see fit using our web dashboard. All applicable providers are enabled by default.

The current version of the Freestar SDK is 5.31.0.

Ad Provider SDK Version Ad Unit Types
AdColony 4.7.2 Fullscreen Interstitial & Rewarded
AppLovin 11.11.3 Fullscreen Interstitial & Rewarded, Banner 320x50
AppLovinMax 11.11.3 Fullscreen Interstitial & Rewarded, Banner 300x250, Banner 320x50
Criteo 4.3.1 Fullscreen Interstitial & Rewarded, Banner 300x250, Banner 320x50
Admob 10.9.0 Fullscreen Interstitial & Rewarded, Banner 300x250, Banner 320x50, Native
Google Ads Manager 10.9.0 Fullscreen Interstitial & Rewarded, Banner 300x250, Banner 320x50, Native
Tapjoy 12.8.0 Fullscreen Rewarded
Unity Ads 4.8.0 Fullscreen Interstitial & Rewarded
Vungle 7.0.1 Fullscreen Interstitial & Rewarded, Banner 300x250, Banner 320x50
Google IMA 3.13.0 Preroll
Nimbus 2.15.0 Fullscreen Interstitial & Rewarded, Banner 300x250, Banner 320x50
TAM (Amazon Publisher Services) 4.7.5 Fullscreen Interstitial & Rewarded, Banner 300x250, Banner 320x50
Pangle 3.7.0 Fullscreen Interstitial & Rewarded, Banner 300x250, Banner 320x50, Native
Hyprmx 6.0.3 Fullscreen Interstitial & Rewarded, Banner 300x250, Banner 320x50
Yahoo 1.14.2 Fullscreen Interstitial, Banner 300x250, Banner 320x50, Native
Ogury 2.1.0 Fullscreen Interstitial & Rewarded, Banner 300x250, Banner 320x50
Prebid 2.1.5 Banner 300x250, Banner 320x50
Fyber 8.2.4 Banner 300x250, Banner 320x50
Smaato 22.1.3 Fullscreen Interstitial & Rewarded, Banner 300x250, Banner 320x50

Project Setup

Your Podfile should have the following:

# Uncomment the next line to define a global platform for your project
platform :ios, '12.0' # minimum ios version

target 'FreestarOBJCSample' do # app name
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!
  pod 'FreestarAds', '~> 5.31.0' # required

  # Only specify the partners for which you want to run ads

   pod "FreestarAds-AdColony", "~> 4.7.2.1"
   pod "FreestarAds-AppLovin", "~> 11.11.3.3"
   pod "FreestarAds-AppLovinMax", "~> 11.11.3.4"
   pod "FreestarAds-Criteo", "~> 4.3.1.1"
   pod "FreestarAds-Fyber2", "~> 8.2.4.3"
   pod 'FreestarAds-GAM', '~> 10.9.0.9'
   pod 'FreestarAds-GAM/Facebook', '~> 10.9.0.9'
   pod 'FreestarAds-Googleadmob', '~> 10.9.0.9'
   pod 'FreestarAds-Googleadmob/Facebook', '~> 10.9.0.9'
   pod "FreestarAds-Hyprmx", "~> 6.0.3.4"
   pod "FreestarAds-Ogury", "~> 2.1.0.3"
   pod "FreestarAds-Prebid", "~> 2.1.5.15"
   pod "FreestarAds-TAM", "~> 4.7.5.7"
   pod "FreestarAds-Tapjoy", "~> 12.8.0.1"
   pod "FreestarAds-Unity", "~> 4.8.0.5"
   pod "FreestarAds-Yahoo", "~> 1.14.2.2"
   pod "FreestarAds-Nimbus", "~> 2.15.0.6"
   pod "FreestarAds-Smaato", "~> 22.1.3.2"
   pod "FreestarAds-Vungle", "~> 7.0.1.3"

# Not M1 compatible pods

pod "FreestarAds-Google", "~> 3.13.0.1"
pod "FreestarAds-Pangle", "~> 3.7.0.2"
end

Once the podfile is setup, enter the Xcode project's base directory in the terminal and run pod install. Then open the generated .xcworkspace project with Xcode.

Info.plist

Some ad networks require adding special parameters in the app's Info.plist file. Below are the partner-specific Info.plist requirements.

Google Ad Manager
<key>GADIsAdManagerApp</key>
<true/>
Google Admob
<key>GADApplicationIdentifier</key>
<string>{YOUR_ADMOB_KEY}</string>
AppLovin
<key>AppLovinSdkKey</key>
<string>{YOUR_APPLOVIN_KEY}</string>
AdColony
<key>NSCalendarsUsageDescription</key>
<string>Adding events</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Taking selfies</string>
<key>NSCameraUsageDescription</key>
<string>Taking selfies</string>
<key>NSMotionUsageDescription </key>
<string>Interactive ad controls</string>

In the above entry, you should change the reasons to be appropriate for your app.

Logging

You can enable detailed logging from the SDK to inspect the ad mediation process in detail via an app's console. This is done by setting a flag in the Info.plist file:

<key>FSTR_LOGGING_ENABLE</key>
<true />

Once this change is made, rebuild the app to see the logs.

❗⚠Warning: For both performance and security reasons, it is not advisable to have detailed logging in production apps. Remove the flag in the Info.plist before submitting to the App Store.

Using the Freestar SDK

To interface with the Freestar ad mediation, have the following at the top of the code file where you want to make use of the SDK:

@import FreestarAds;

GDPR Support

Freestar is GDPR-ready and supports the IAB Standards for GDPR compliance.

Use the following simple api in conjunction with your existing Consent Management Provider. If you do not have a CMP solution, that’s ok, too! Our mediation sdk will detect if the user is in the EU and automatically apply GDPR actions to the ad request. So, by default, you do not have to do any extra work to use our sdk in a GDPR-compliant fashion.

// Save GDPR consent string
[[Freestar privacySettings] subjectToGDPR:gdprApplies withConsent:gdprConsentString];

Initialize Freestar

Freestar must be initialized in the application:didFinishLaunchingWithOptions: of your AppDelegate (or at another time as close as possible to the app launch). This gives the prefetch mechanism time work and thus, makes ad fill more likely when a request is made.

static NSString* const FREESTAR_APP_KEY = @"P8RIA3";

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [Freestar initWithAppKey:FREESTAR_APP_KEY];

    //more initialization code

    return YES;
}
Note: if you would like to see ads from TAM (Amazon Publisher Services), make sure your `AppDelegate` implements the `window` property from `UIApplicationDelegate` protocol:

@property(nullable, nonatomic) UIWindow* window;

Interstitial Ad

Implement the FreestarInterstitialDelegate protocol in one of your classes:

-(void)freestarInterstitialLoaded:(FreestarInterstitialAd *)ad {}
-(void)freestarInterstitialFailed:(FreestarInterstitialAd *)ad because:(FreestarNoAdReason)reason {}
-(void)freestarInterstitialShown:(FreestarInterstitialAd *)ad {}
-(void)freestarInterstitialClicked:(FreestarInterstitialAd *)ad {}
-(void)freestarInterstitialClosed:(FreestarInterstitialAd *)ad {}

This allows your app to listen to ad events and act appropriately. You will pass an instance of this object to the Freestar SDK when loading interstitial ad. In the current sample app, the class implementing this protocol is the ViewController, and the implementation is located in ViewController+FreestarAds.m

//self is the object that implements FreestarInterstitialDelegate
self.interstitial = [[FreestarInterstitialAd alloc] initWithDelegate:self];

//You can load associated to a placement as follows, or pass in
//nil for the default placement
[interstitial loadPlacement:@"interstitial_p1"];
If you plan to use more than one placement in your app, please adhere to the placement naming convention as follows:

"my_placement_name_pN", where N is the number of your placement.

For example, let us assume you are using 2 interstitial ad placements in your game or app. The first placement would be the default placement; simply do not specify a placement name by calling the loadPlacement: method with nil as the argument. The second placement would be, for example, "my_search_screen_p1". The ending "p1" tells the SDK to use the second placement you created in our web dashboard for the interstitial ad unit.

This placement format is the same for all the other ad units, such as rewarded ads and banner ads.

When the interstitial ad is ready, the freestarInterstitialLoaded: callback will occur.

-(void)freestarInterstitialLoaded:(FreestarInterstitialAd *)ad {
  //self in this case should be an instance of UIViewController
  [ad showFrom:self];  //You can display the ad now OR show it later; your choice.
}

There are other callbacks that will occur in other events, such as in the rare event where a load ad request does not result in a fill. Please see the ViewController+FreestarAds.m on this sample for those details.

❗⚠Warning: Attempting to load a new ad from the freestarInterstitialFailed:because: method is strongly discouraged. If you must load an ad from freestarInterstitialFailed:because:, limit ad load retries to avoid continuous failed ad requests in situations such as limited network connectivity.
The clicked callback is no longer reported for Googleadmob or GAM ads. This also applies to banner ads as well as interstitial.

Custom Targeting

Freestar Ads allows for custom targeting parameters that will be sent on to our Google Ads Manager adapter.

[interstitial addCustomTargeting:@"key1" as:@"value1"]; //optional
[interstitial addCustomTargeting:@"key2" as:@"value2"]; //optional
Note: the addCustomTargeting:as: method works in the same manner on rewarded, banner and preroll ads.

Banner Ad

Freestar supports 300x250 and 320x50 banner ad formats and allows you to control the refresh intervals remotely.

    smallBanner = [[FreestarBannerAd alloc] initWithDelegate:self     
      andSize:FreestarBanner320x50];
    [smallBanner loadPlacement:nil]; //or pass in specific placement

When the banner ad is ready, the freestarBannerLoaded: callback will occur.

-(void)freestarBannerLoaded:(FreestarBannerAd *)ad {
  NSLog(@"banner ad as been loaded: %@", ad);
}

If you insert the banner ad into the view hierarchy at this point, the ad will display automatically.

Banner ads can also be specified in Interface Builder layout and will be automatically loaded. If you do this, however, you will need to set the size and delegate properties on the ad object before calling loadPlacement:

The 320x50 ad size a standard for iPhones, on iPads, the corresponding banner ad size is 728x90. By default, a banner ad created with FreestarBanner320x50 as the size parameter will be rendered as a 320x50 ad on iPhones, and as a 728x90 ad on iPads. If you want to always render the ad as 320x50, regardless of device, you should set the fixedSize flag on the ad object:

smallBanner = [[FreestarBannerAd alloc] initWithDelegate:self andSize:FreestarBanner320x50];
smallBanner.fixedSize = YES;
[smallBanner loadPlacement:nil]; //or pass in specific placement

This will always show the in 320x50 size, no matter what device your app is running on.

Dynamic Banner Size

Since 5.20 SDK version, dynamic sizes are supported for mrec banner. This means, the banner ad size returned can be 320x50, 300x250, or 0x0 (native). Native ad size(s) are fluid, so app layout will need to manage dynamic size. Subsequently, for added convenience, we have created a banner callback to inform the delegate when ad size(s) have changed:
- (void)didUpdateBanner:(FreestarBannerAd *)ad withSize:(CGSize)newSize native:(BOOL)isNative {
    // TODO: handle size changes, if needed
}

Rewarded Ad

A common myth regarding Rewarded Ads is publishers are required to give something to the user. But, that's not true. You can simply tell the user they must watch the ad in order to be able to proceed to the next level or proceed to content.

Implement the FreestarRewardedDelegate protocol in one of your classes:

-(void)freestarRewardedLoaded:(FreestarRewardedAd *)ad {}
-(void)freestarRewardedFailed:(FreestarRewardedAd *)ad because:(FreestarNoAdReason)reason {}
-(void)freestarRewardedShown:(FreestarRewardedAd *)ad {}
-(void)freestarRewardedClosed:(FreestarRewardedAd *)ad {}
-(void)freestarRewardedFailedToStart:(FreestarRewardedAd *)ad because:(FreestarNoAdReason)reason {}
-(void)freestarRewardedAd:(FreestarRewardedAd *)ad received:(NSString *)rewardName amount:(NSInteger)rewardAmount {}

This allows your app to listen to ad events and act appropriately. You will pass an instance of this object to the Freestar SDK when loading rewarded ad. In the current sample app, the class implementing this protocol is the ViewController, and the implementation is located in ViewController+FreestarAds.m

//this may be overriden in the ad portal
FreestarReward *rew = [FreestarReward blankReward];
rew.rewardName = @"Coins";
rew.rewardAmount = 1000;
rew.userID = @"CoolGuy";
rew.secretKey = @"Bx34da3yn";

        //Note: If you want to use server-to-server rewarded callbacks, the Freestar team will provide
        //      you with a secret key and only that will work.
        //      However, if you want to use client-side only rewarded callbacks, then you can supply
        //      your own "secretKey" or null.

//self is the object that implements FreestarRewardedDelegate
self.rewarded = [[FreestarRewardedAd alloc] initWithDelegate:self
  andReward:rew];
[rewarded loadPlacement:@"rewarded_p1"]; //or pass in nil for default

When the rewarded ad is ready, the freestarRewardedLoaded: callback will occur.

-(void)freestarRewardedLoaded:(FreestarRewardedAd *)ad {
  //self in this case should be an instance of UIViewController
  [ad showFrom:self];  //You can display the ad now OR show it later; your choice.
}

When the user has fully watched the rewarded ad (or when the given ad partner determines sufficient watch time for the reward), the following callback will occur:

-(void)freestarRewardedAd:(FreestarRewardedAd*)ad received:(NSString *)rewardName {} amount:(NSInteger)rewardAmount {
  //allow user to proceed to app content or next level in app/game
  //can use the name/amount to show change in UI
}

When the user has closed the rewarded ad, the following callback will occur:

-(void)freestarRewardedClosed {}
If the user does not watch the rewarded ad thru to completion, freestarRewardedAd:received:amount: will not occur. However, the freestarRewardedClosed will always occur when the rewarded ad is dismissed regardless if the user watched the entire rewarded ad or not.
❗⚠ Please assume that ads will expire in about 1 hour after the loaded callback. Meaning, you may cache an ad in your app or game, but must be displayed with the allotted hour.

Native Ad

Medium and Small Native ADs

ad images

Freestar supports the Native Ad unit. Native ads are well suited for content-based or feed-based apps because developers can actually customize the ad layout to better match their user experience.

Get Started

        @import FreestarAds;
        ...

        self.nativeAd = [[FreestarNativeAd alloc] initWithDelegate:self andSize:FreestarNativeSmall]; //or FreestarNativeMedium
        [self.nativeAd loadPlacement:nil];
        //Note: you may pass in a "placement" parameter in loadPlacement but it requires prior remote staff setup
        

Assuming you implemented the FreestarNativeAdDelegate protocol:

- (void)freestarNativeClosed;
- (void)freestarNativeFailed:(nonnull FreestarNativeAd *)ad because:(FreestarNoAdReason)reason;
- (void)freestarNativeLoaded:(nonnull FreestarNativeAd *)ad;
- (void)freestarNativeShown:(nonnull FreestarNativeAd *)ad;

and set the delegate object on nativeAd, when the native ad is ready, the freestarNativeLoaded: callback will occur.

- (void)freestarNativeLoaded:(nonnull FreestarNativeAd *)ad {
    self.nativeAd.center = self.view.center; //choose the position of your ad within your app view 
    [self.view addSubview:self.nativeAd]
}

Another Way

Another way to display native ads is to put FreestarNativeAd directly into your Interface Builder layout by placing a view where you want and assigning its class to be FreestarNativeAd.

NOTE: If you choose this route, then you do not need any code in Objective-C or Swift since the ad will automatically be fetched and displayed. Also, if you need to set targeting parameters in the AdRequest, then please use the programmatic approach (above) and do not put the native ad in the layout. However, to receive the delegate callbacks listed above, you will need to assign the delegate object to the ad from the XIB once it is loaded.

Native Templates

Freestar supports two native ad templates: small and medium

By default, you are not required to modify the native ad templates. However, if you want to modify, keep reading...

Modify Small and/or Medium Templates

If you wish to modify the templates, get a copy here.

Get the Freestar-Native-Medium-Custom.xib and Freestar-Native-Small-Custom.xib files and add them to your App bundle with Xcode. You may edit them with Interface Builder to better meet your needs. However, when you modify either of the .xib files, please do not remove any elements, rename any IBOutlets, or change the tag property on any element in the hierarchy. To drop back to using the default Freestar templates, simply remove the custom files from your app bundle.

Sample Project

All of this and more, such as Preroll Ads can be seen in the sample ViewController+FreestarAds.m:

https://github.com/freestarcapital/SDK_documentation_iOS/blob/master/FreestarOBJCSample/FreestarOBJCSample/ViewController+FreestarAds.m

⚠️ **GitHub.com Fallback** ⚠️