-
Couldn't load subscription status.
- Fork 15
integration guide ios
/*
Title: Integration Guide for iOS
Description: A guide to integrating the Unity Ads SDK for iOS
Sort: 11
*/
Unity Ads is a monetization tool that allows you to display video trailers of other games to your users, earn money with each view, and reward users with a virtual item. To monetize your users with Unity Ads, integrate the Unity Ads SDK into your game. This document will guide you through that process.
Note: These instructions are meant for non-unity integrations, if you are using Unity please refer to Unity Specific instructions here
Unity Ads Integration consists of the following parts:
- Integrating Unity Ads to your iOS game
- Configuring Unity Ads on the Unity Ads Admin Panel
Note: If you have not done so already, download the Unity Ads SDK from GitHub.
The process of integrating Unity Ads to your iOS game is fairly straightforward and does not require heavy integration. The process of using Unity Ads in your applications is described below in outlined steps:
- Import (drag and drop)
UnityAds.frameworkandUnityAds.bundleinto your Xcode project from the root directory of your SDK folder - Initialize the SDK with your Unity Ads gameId
- Verify that there are campaigns available to the user
- Show Unity Ads to user
- Wait for the user to complete watching the video, and reward the item to the user
Your project will needs to include the following frameworks to compile Unity Ads
AdSupport.framework, AVFoundation.framework, CFNetwork.framework, CoreFoundation.framework
CoreMedia.framework, CoreTelephony.framework, StoreKit.framework, SystemConfiguration.framework
- Select Project Settings > Build Phases
- Expand "Link Binary with Libraries" section
- For each framework, click "+", and add the framework to the Project
The actual code-level integration is described in the sections below. Should you have any problems integrating the product, log a ticket with us by emailing [email protected].
The first step is to add the UnityAds class to your app delegate. Firstly, you need to include the necessary headers:
#import <UnityAds/UnityAds.h>Then, to your -application:didFinishLaunchingWithOptions: -method, add the initialization code for Unity Ads by passing your Unity Ads gameId, and your root view controller.
// Initialize Unity Ads
[[UnityAds sharedInstance] startWithGameId:@"1003843" andViewController:myViewController]; //replace game ID with your ownNote: Replace the YOUR_GAME_ID_HERE section above with your Unity Ads gameId. You can find this in the Unity Ads Admin Panel under the section
“Publisher > Games”.
If for some reason you cannot pass the view controller to Unity Ads at the time when it is initialized, you can init Unity Ads with just calling startWithGameId, without the view controller.
Example:
[[UnityAds sharedInstance] startWithGameId:@"1003843"];Before you can use Unity Ads, you need to pass the view controller via the setViewController method:
- (void)setViewController:(UIViewController *)viewController;Example:
[[UnityAds sharedInstance] startWithGameId:1003843];
// Other initialization code
// ...
// Add the view controller
[[UnityAds sharedInstance] setViewController:myViewController];Your ViewController needs to act as a delegate for Unity Ads. First, you must register your ViewController as the delegate.
[[UnityAds sharedInstance] setDelegate:self];The delegate must implement the following method at minimum:
- (void)unityAdsVideoCompleted:(NSString *)rewardItemKey skipped:(BOOL)skippedThis delegate method is called when the user has completed watching a video with Unity Ads, and they should be granted the virtual item offered as a reward if skipped is false.
When you have initialized the Unity Ads SDK and added your ViewController as the Unity Ads delegate, you can start showing ads in your application. Prior to showing ads, you should always check if there is an ad available for the current user. To see if the ad unit can be shown and whether there is inventory available, use the canShow method. When you have done these checks, you can show an ad to the user using the show method.
This functionality allows different configurations for different ads setup in the Unity Ads Admin Panel. Typical example would be a game that shows both: incentivized (watch video get 100 coins) and non-incentivized ads. Usually ad skipping is disabled for incentivized ads and enabled for non-incentivized ads.
You should call setZone just before calling show.
The zoneId is defined in the Unity Ads Admin Panel when defining an Ad-placement.
The rewardItemKey is defined in the Unity Ads Admin Panel when defining a reward item.
// Set the zone before checking readiness or attempting to show.
[[UnityAds sharedInstance] setZone:@"rewardedVideo"];
// Use the canShow method to check for zone readiness,
// then use the canShowAds method to check for ad readiness.
if ([[UnityAds sharedInstance] canShow])
{
// If both are ready, show the ad.
[[UnityAds sharedInstance] show];
}When the ad view is closed, it will automatically remove itself from the ViewController. If you need to close the ad view from your code, you can call the hide method:
[[UnityAds sharedInstance] hide]Note: The way this API works is that you either don't call setZone at all and use the default ad placement settings everywhere, or you explicitly call setZone always before calling show.
You can pass an optional parameter for Unity Ads by passing the show method a dictionary that defines the requested properties.
-
kUnityAdsOptionGamerSIDKey:@"playerName"– You can give an offer or user ID to Unity Ads through this parameter.
Example:
[[UnityAds sharedInstance] show:@{
kUnityAdsOptionGamerSIDKey:@"gamerSid"}]If you are not rewarding your users for videos you can safely ignore this section.
Note: The item key functionality is no longer supported.
It will be deprecated in a future SDK release.
Once the user has completed the video ad, the Unity Ads SDK will call the -unityAdsVideoCompleted:rewardItemKey:skipped: delegate method. At this point, you should reward the user with the virtual item that was promised to them. This delegate method passes you the item key of the reward item as a parameter. See section titled “About Item Keys” below to read more about item keys.
unityAdsVideoCompleted:rewardItemKey:skipped:now has a boolean indicating whether user skipped the video or not. If user skips the video he/she shouldn't get the reward, but that is up to developer.
Also note: that the call to the
-unityAdsVideoCompleted:rewardItemKey:skipped: methodis not a guarantee of the Unity Ads adView being closed, for that, please use the-unityAdsWillHide: delegate method.
Item keys are a way to differentiate between different rewards in your game. As the redeeming of the virtual items is done inside your game code, you need a way to change the reward item without updating your game. Therefore, the Unity Ads SDK allows you to configure an item key on the Unity Ads Admin Panel that will be passed to your code. It is recommended that you add as many reward items as possible to your code, and differentiate between them with different item keys. This allows you to change the item without changing your code.
Example of multiple items
- (void)unityAdsVideoCompleted:(NSString *)rewardItemKey skipped:(BOOL)skipped
{
NSLog(@"unityAdsVideoCompleted:rewardItemKey:skipped: -- key: %@", rewardItemKey);
if([rewardItemKey isEqualToString:@"item_armor"]) {
[self awardUserWithArmor]
} else if([rewardItemKey isEqualToString:@"gold_50k"]) {
[self awardUserWithGold50]
} else if([rewardItemKey isEqualToString:@"gold_100k"]) {
[self awardUserWithGold100]
}
}Note: Multiple item support is available in SDK version 1.0.3 or newer.
To create a more flexible incentivization for the users, the Unity Ads SDK allows you to configure multiple reward items in the Unity Ads Admin Panel, so your integration can at run-time decide which reward item should be used. This feature is useful is you’re for example providing a free boost in your game, and there are multiple boosts available that you want the user to be able to pick from.
Each integration needs to define a default reward item in the Admin Panel, which will be used if you do not explicitly choose a reward item in your client-side code.
You can change the reward item to be shown to the user by calling the - (BOOL)setRewardItemKey:(NSString *)rewardItemKey; method of the Unity Ads instance.
Example:
-(void) showToUser
{
// Get the reward item key the user selected in our game's offer menu
NSString* reward = [myGameUI getRewardItemElement];
// Tell Unity Ads to use this reward
/* Note: The Unity Ads UI is already inited in the background, and this call will cause it to change
to show the new reward item and if you show the Unity Ads view _immediately_ after calling this,
there may be some flickering, so make sure to call setRewardItemKey as soon as possible in your code */
[[UnityAds sharedInstance] setRewardItemKey:reward];
// Show Unity Ads
[[UnityAds sharedInstance] show];
/* Now when the user completes the video, the itemKey passed
to the unityAdsVideoCompleted:rewardItemKey:skipped: delegate method
will be the one set in this method using the
setRewardItemKey method
*/
}You can query the currently set reward item using the - (NSString *)getCurrentRewardItemKey; method. All available reward items can be queried using the - (NSArray *)getRewardItemKeys; method which returns an NSArray* of the item keys. You can query the item details (name, picture) using the - (NSDictionary *)getRewardItemDetailsWithKey:(NSString *)rewardItemKey; method. This method returns an NSDictionary* object that contains two keys that have the following values:
Key kUnityAdsRewardItemPictureKey // contains the URL to the picture as a value
Key kUnityAdsRewardItemNameKey // contains the human readable name (e.g. “100 Coins!”) as a valueExample:
NSArray* items = [[UnityAds sharedInstance] getRewardItemKeys];
for (id itemKey in items) {
NSDictionary* itemDetails = [[UnityAds] sharedInstance] getRewardItemDetailsWithKey:itemKey];
NSLog(@"Item %@: Picture: %@, Name: %@",
itemKey,
[itemDetails objectForKey:kUnityAdsRewardItemPictureKey]
[itemDetails objectForKey:kUnityAdsRewardItemNameKey]);
}To test your integration, you can run Unity Ads in test mode. This can be achieved by calling the setTestMode:(BOOL)testModeEnabled method of the UnityAds class prior to calling startWithGameId. Example:
// TEST MODE: Do not use in production apps
[[UnityAds sharedInstance] setTestMode:YES];
[[UnityAds sharedInstance] setDebugMode:YES];
[[UnityAds sharedInstance] startWithGameId:@"YOUR_GAME_ID_HERE" andWithViewController:myViewController];To configure Unity Ads for your iOS game, log into the Unity Ads Admin Panel at https://unityads.unity3d.com/admin/.
First, you need to register your game in the Unity Ads Admin Panel. For this, you need the iTunes application ID or the iTunes URL for your application. For example:
or
To register the game, go to the Games page from menu of the Unity Ads Admin Panel and click Add New Game.
After the game has been successfully added, it will show up in the games listing. Click on the game to access further options. Click 'Monetizing Settings' to open up the game’s integration details. On this page, you will find the Unity Ads gameId that you need to use when calling startWithGameId.
Here you may also change the options of the Ad Placements you want to have in your game. You can create additional placements with different settings for e.g. tracking purposes. Each placement's settings are individually adjustable.
- Unity Ads与GDPR
- 流量变现常见问题(中文FAQ)
- 《基本操作与集成手册》
- 《Unity Ads开发者后台操作手册》
- 聚合接入指南
- 关于中国大陆地区Android商店的声明
- COPPA设置及其影响
- DeltaDNA案例分析
- 2020手游变现分析报告要点分享(英文)
- Unity2020广告效果基准报告(英文)
- 使用Unity Ads的十个常见问题
- 视频广告设计指南
- 广告位(Placement)的介绍
- 统计API
- 开发者后台操作指南
- 广告位与广告过滤
- 变现数据分析
- 变现盈利与支付流程
- 2020手游变现分析报告要点分享(英文)
- Unity中app-ads.txt设置指南
- DeltaDNA案例分析
- Unity Developer Network 账号转移
- 《基本操作与集成手册》
- 《Unity Ads开发者后台操作手册》
- COPPA设置及其影响
- 黑名单文件模版
- 设置底价文件模版
- 应用被Google Play下架处理办法