Freestar Ads Mediation Xamarin iOS - freestar-archive/freestarcapital-SDK_documentation_iOS GitHub Wiki
Freestar Ads Mediation provides support for Xamarin iOS in C# by providing the necessary NuGet package.
Note: The supported list for Xamarin may differ from our Native iOSAd Provider | SDK Version | Ad Unit Types |
Admob | 9.2.0.3 | Fullscreen Interstitial & Rewarded, Banner 300x250, Banner 320x50 |
Google Ads Manager | 9.2.0.3 | Fullscreen Interstitial & Rewarded, Banner 300x250, Banner 320x50 |
TAM (Amazon Publisher Services) | 4.4.3.3 | Fullscreen Interstitial & Rewarded, Banner 320x50 |
• Before we begin, you must have a working Xamarin app running on an iOS device. This document will not show how to create a Xamarin app for iOS as that would be beyond the scope of Freestar Ads Mediation.
• Your Xamarin app must target Xamarin.iOS 11.0 or higher
.
NuGet Package Name | Version |
Xamarin.Essentials | 1.7.3 |
Xamarin.Build.Download | 0.11.2 |
Xamarin.iOS.FreestarAds | 5.13.0 |
Xamarin.iOS.FreestarAdsAdmobAdapter | 9.2.0.3 |
Xamarin.iOS.FreestarAdsGAMAdapter | 9.2.0.3 |
Xamarin.iOS.FreestarAdsTAMAdapter | 4.4.3.3 |
Some ad networks require adding special parameters in the app's Info.plist
file. Below are the partner-specific Info.plist
requirements.
<key>GADIsAdManagerApp</key>
<true/>
<key>GADApplicationIdentifier</key>
<string>{YOUR_ADMOB_KEY}</string>
<key>AppLovinSdkKey</key>
<string>{YOUR_APPLOVIN_KEY}</string>
<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.
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 the logging API to true (enabled):
Freestar.SetLoggingEnabled(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.
Note: Any Xamarin class calling Freestar code will need the following directive: using com.freestar.ios.ads;
In the FinishedLaunching
of your starting AppDelegate:
Freestar.InitWithAppKey("XqjhRR"); // this is a test key for test use only, make sure to replace this with production key for App Store releases
How to display full screen Interstitial ads:
First, implement the IFreestarInterstitialDelegate
interface.
Note: How to implement an interface in C# is beyond the scope of this document.
FreestarInterstitialAd interstitialAd = new FreestarInterstitialAd([YOUR IFreestarInterstitialDelegate]);
interstitialAd.LoadPlacement(null); //Note: you may pass a "placement" string instead.
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 null 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 you receive FreestarInterstitialLoaded
from your IFreestarInterstitialDelegate
, you may show the ad:
interstitialAd.ShowFrom([YOUR App's current top ViewController]);
How to display full screen Rewarded ads:
First, implement the IFreestarRewardedDelegate
interface.
Note: How to implement an interface in C# is beyond the scope of this document.
Choose the reward name and amount, and pass it to the created ad:
FreestarReward rwd = FreestarReward.BlankReward();
rwd.RewardAmount = 100;
rwd.RewardName = "gems";
FreestarRewardedAd rewardedAd = new FreestarRewardedAd(YOUR IFreestarRewardedDelegate], rwd);
rewardedAd.LoadPlacement(null); //Note: you may pass a "placement" string instead.
When you receive FreestarRewardedLoaded
from your IFreestarRewardedDelegate
, you may show the ad:
rewardedAd.ShowFrom([YOUR App's current top ViewController]);
How to display Banner ads:
FreestarBannerAd bannerAd = new FreestarBannerAd(
[YOUR IFreestarBannerAdDelegate],
FreestarBannerAdSize.FreestarBanner320x50);
//For MREC size, use FreestarBannerAdSize.FreestarBanner300x250
bannerAd.LoadPlacement(null); //Note: you may pass a "placement" string instead.
Next, you will receive FreestarBannerLoaded
of your IFreestarBannerAdDelegate
.
Here is an example implementation:
public void IFreestarBannerAdDelegate.FreestarBannerLoaded(FreestarBannerAd ad)
{
ad.Center = new CGPoint(
YOUR_AdContainer.Frame.Width / 2,
YOUR_AdContainer.Frame.Height / 2);
YOUR_AdContainer.AddSubview(ad);
}