Unity Ads iOS SDK API reference
Use the UnityAds.h
library to implement basic ad content, such as rewarded or non-rewarded video, interstitial, or banner ads.
#import "UnityAds.h"
This article contains the following API documentation:
Classes
Enums
Delegates
UnityAdsInitializationDelegate
UnityAdsLoadDelegate
UnityAdsShowDelegate
UADSBannerDelegate
UADSBannerAdRefreshViewDelegate
Classes
UnityAds
#import <UnityAds/UnityAds.h>
Use this namespace to implement basic ad content, such as rewarded or non-rewarded video, interstitial, or banner ads.
initialize
+ (void) initialize: (NSString *)gameId
testMode: (BOOL)testMode
initializationDelegate: (nullable id<UnityAdsInitializationDelegate>)initializationDelegate;
}
Initializes the ads service, with a specified Game ID, test mode status, and initialization delegate.
Parameter | Description |
---|---|
| The platform-specific Unity game identifier for your project, found on the Unity Ads Monetization dashboard. |
| Use Test mode to test your integration without serving live ads. Use |
| Optionally enables the SDK with |
load
+ (void)load: (NSString *)placementId options: (UADSLoadOptions *)options loadDelegate: (nullable id<UnityAdsLoadDelegate>)loadDelegate {
[UADSLoadModule.sharedInstance loadForPlacementID: placementId
options: options
loadDelegate: loadDelegate];
}
Loads ad content for a specified Ad Unit. You must call load
before calling show
.
Parameter | Description |
---|---|
| The identifier for the Ad Unit you want to load with ad content. |
| A collection of options for modifying ad load behavior. |
| Optionally loads ad content with |
isReady
Removed in SDK version 4.0. For more information, refer to the deprecated API classes.
+ (BOOL)isReady: (NSString *)adUnitId {
return [UnityServices isSupported] && [UnityServices isInitialized] && [UADSPlacement isReady: adUnitId];
}
Returns YES
if an ad is ready to show in the specified Ad Unit. If you initialized the SDK with enablePerPlacementLoad
enabled, you must call load
before calling show
.
Parameter | Description |
---|---|
| The identifier for the Ad Unit you want to query. |
Note: If you call isReady
without specifying an Ad Unit ID, the method returns results for the Unity Standard Placement.
.
show
+ (void)show: (UIViewController *)viewController placementId: (NSString *)placementId showDelegate: (nullable id<UnityAdsShowDelegate>)showDelegate {
[self show: viewController
adUnitId: placementId
options: [UADSShowOptions new]
showDelegate: showDelegate];
}
Displays loaded ad content in a specified Ad Unit.
Parameter | Description |
---|---|
| The identifier for the Ad Unit you want to show. |
| A collection of options for modifying ad show behavior. |
| Optionally shows content with |
Note: If you call show
without specifying an Ad Unit ID, the method shows loaded content in the Unity Standard Placement. In SDK versions 4.0 and later, you must call this method with an Ad Unit ID.
addDelegate
Removed in SDK version 4.0. For more information, refer to the deprecated API classes.
+ (void)addDelegate: (__nullable id<UnityAdsDelegate>)delegate {
[UADSProperties addDelegate: delegate];
}
Adds a listener delegate that will recieve Unity Ads callbacks. In versions 3.1.0 and later, you can register multiple listeners. This is especially helpful for mediation customers.
Parameter | Description |
---|---|
| A listener for Unity Ads callbacks. |
removeDelegate
Removed in SDK version 4.0. For more information, refer to the deprecated API classes.
+ (void)removeDelegate: (id<UnityAdsDelegate>)delegate {
[UADSProperties removeDelegate: delegate];
}
Removes an active UnityAdsDelegate
listener.
Parameter | Description |
---|---|
| A listener for Unity Ads callbacks. |
setDebugMode
+ (BOOL)getDebugMode {
return [UnityServices getDebugMode];
}
Controls the amount of logging output from the SDK. Set to YES
for more robust logging.
getDebugMode
+ (void)getDebugMode: (BOOL)enableDebugMode {
[UnityServices setDebugMode: enableDebugMode];
}
Returns YES
if the SDK is is in debug mode, and NO
if it isn't.
getVersion
+ (NSString *)getVersion {
return [UnityServices getVersion];
}
Returns the current version of the Unity Ads SDK.
isInitialized
+ (BOOL)isInitialized {
return [USRVSdkProperties isInitialized];
}
Returns YES
if the SDK is initialized successfully, and NO
if it isn't.
UADSLoadOptions
#import <UnityAds/UADSBaseOptions.h>
@interface UADSLoadOptions : UADSBaseOptions
@property (nonatomic, readwrite) NSString *adMarkup;
@end
This class contains optional metadata to include with the load
method. Customers using header bidding in third-party mediation should use this in cases where a bidder from the Unity network wins the ad auction.
setAdMarkup
- (void)setAdMarkup: (NSString *)adMarkup
This method takes the ad markup returned from the bidder service. When a bidder from Unity's ad network wins a header bidding auction, the Unity Ads SDK receives ad markup from the mediated exchange. The ad markup string contains information needed for Unity to load and show the ad.
UADSBannerView
@interface UADSBannerView : UIView
Use this class to implement banner ads. Unity Ads versions 3.3 and later support multiple banner instances through a single Ad Unit.
initWithPlacementId
-(instancetype)initWithPlacementId:(NSString *)placementId size:(CGSize)size;
Implements a banner view using an Ad Unit ID and banner size. Call initWithPlacementId
to initialize the object, then load
to load ad content. Note that the banner object accesses lifecycle events through its UADSBannerViewDelegate
listener.
Parameter | Description |
---|---|
| The banner's Ad Unit ID. |
| The |
Note: Using UADSBannerView
to call a banner ad attempts to load content once, with no refreshing. If the banner returns no fill, you can destroy it and create a new one to try again. Unity recommends this method for mediated customers.
load
- (void)load;
The basic method for requesting an ad for the banner.
Enums
UnityAdsPlacementState
Removed in SDK version 4.0. For more information, refer to the deprecated API classes.
typedef NS_ENUM(NSInteger, UnityAdsPlacementState)
The enumerated states of an Ad Unit.
Value | Description |
---|---|
| The Ad Unit is ready to show ads. |
| The Ad Unit is not available. |
| The Ad Unit was disabled. |
| The Ad Unit is waiting to be ready. |
| The Ad Unit has no ad to show. |
UnityAdsFinishState
Removed in SDK version 4.0. For more information, refer to the deprecated API classes.
typedef NS_ENUM(NSInteger, UnityAdsFinishState)
The enumerated states of the user’s interaction with the ad. The SDK passes this value to the unityAdsDidFinish
callback method when the ad completes.
Value | Description |
---|---|
| Indicates that the ad failed to complete due to a Unity error. |
| Indicates that the user skipped the ad. |
| Indicates that the ad finished playing. |
UnityAdsInitializationError
typedef NS_ENUM (NSInteger, UnityAdsInitializationError)
The enumerated reasons for SDK initialization to fail.
Value | Description |
---|---|
| An error occurred due to the environment or internal services. |
| An error occurred due to invalid arguments in the Initialize method. |
| An error occurred due to a URL being blocked. |
UnityAdsLoadError
typedef NS_ENUM (NSInteger, UnityAdsLoadError)
The enumerated reasons for an Ad Unit failing to load.
Value | Description |
---|---|
| The ad failed to load due to the SDK not being initialized. |
| The ad failed to load due to an internal Unity Ads service error. |
| The ad failed to load due to invalid arguments in the |
| The ad failed to load because no content was available from the network. |
| The ad failed to load within the specified timeframe. |
UnityAdsShowCompletionState
typedef NS_ENUM (NSInteger, UnityAdsShowCompletionState)
The enumerated causes for the ad to have finished.
Value | Description |
---|---|
| Indicates that the user skipped the ad. |
| Indicates that the ad played in its entirety. This typically indicates that the user can be rewarded for watching the full ad. |
UnityAdsShowError
typedef NS_ENUM (NSInteger, UnityAdsShowError)
The enumerated reasons for an Ad Unit failing to show.
Value | Description |
---|---|
| The ad failed to show due to the SDK not being initialized. |
| The ad failed to show because the Ad Unit was not ready. |
| The ad failed to show because of a media player error. |
| The ad failed to show due to invalid arguments in the |
| The ad failed to show because of an internet connection error. |
| The ad failed to show because an ad was already showing. |
| The ad failed to show due to an internal Unity Ads service error. |
UnityAdsError
Removed in SDK version 4.0. For more information, refer to the deprecated API classes.
typedef NS_ENUM (NSInteger, UnityAdsError)
The enumerated causes of a Unity Ads error emitted through the unityAdsDidError
callback.
Value | Description |
---|---|
| The Unity Ads service is currently uninitialized. |
| An error occurred in the initialization process. |
| Unity Ads initialization failed due to invalid parameters. |
| An error occurred due to the video player failing. |
| Initialization of the Unity Ads service failed due to an invalid environment. |
| An error occurred due to an ad blocker. |
| An error occurred due to inability to read or write a file. |
| An error occurred due to a bad device identifier. |
| An error occurred when attempting to show an ad. |
| An internal Unity Ads service error occurred. |
UnityAdsBannerPosition
The enumerated positions you can set as an anchor for banner ads.
Value | Description |
---|---|
| Anchor the banner to the top-left of the screen. |
| Anchor the banner to the top-center of the screen. |
| Anchor the banner to the top-right of the screen. |
| Anchor the banner to the bottom-left of the screen. |
| Anchor the banner to the bottom-center of the screen. |
| Anchor the banner to the bottom-right of the screen. |
| Anchor the banner to the center of the screen. |
| Do not anchor the banner. |
Delegates
UnityAdsInitializationDelegate
@protocol UnityAdsInitializationDelegate <NSObject>
- (void)initializationComplete;
- (void)initializationFailed: (UnityAdsInitializationError)error withMessage: (NSString *)message;
@end
Implement this delegate to handle initialize
results.
initializationComplete
This callback method handles logic for the SDK successfully initializing.
initializationFailed
This callback method handles logic for the SDK failing to initialize.
Parameter | Description |
---|---|
| The |
| A message associated with the error. |
UnityAdsLoadDelegate
@protocol UnityAdsLoadDelegate <NSObject>
- (void)unityAdsAdLoaded: (NSString *)placementId;
- (void)unityAdsAdFailedToLoad: (NSString *)placementId
withError: (UnityAdsLoadError)error
withMessage: (NSString *)message;
@end
Implement this delegate to handle load
results.
unityAdsAdLoaded
This callback method handles logic for the Ad Unit successfully loading.
Parameter | Description |
---|---|
| The identifier for the Ad Unit that loaded content. |
unityAdsAdFailedToLoad
This callback method handles logic for the Ad Unit failing to load.
Parameter | Description |
---|---|
| The identifier for the Ad Unit that failed to load content. |
| The UnityAdsLoadError that caused the load to fail. |
| A message associated with the error. |
UnityAdsShowDelegate
@protocol UnityAdsShowDelegate <NSObject>
- (void)unityAdsShowComplete: (NSString *)adUnitId withFinishState: (UnityAdsShowCompletionState)state;
- (void)unityAdsShowFailed: (NSString *)adUnitId withError: (UnityAdsShowError)error withMessage: (NSString *)message;
- (void)unityAdsShowStart: (NSString *)adUnitId;
- (void)unityAdsShowClick: (NSString *)adUnitId;
@end
Implement this delegate to handle show
results.
unityAdsShowComplete
This callback method handles logic for the ad finishing.
Parameter | Description |
---|---|
| The identifier for the Ad Unit showing the content. |
| Indicates whether the ad was skipped or completed. |
unityAdsShowStart
This callback method handles logic for the ad starting to play.
Parameter | Description |
---|---|
| The identifier for the Ad Unit showing content. |
unityAdsShowClick
This callback method handles logic for the user clicking on the ad.
Parameter | Description |
---|---|
| The identifier for the Ad Unit showing content. |
unityAdsShowFailed
This callback method handles logic for the Ad Unit failing to show content.
Parameter | Description |
---|---|
| The identifier for the Ad Unit that failed to show content. |
| The |
message | A message associated with the error. |
UnityAdsDelegate
Removed in SDK version 4.0. For more information, refer to the deprecated API classes.
@protocol UnityAdsDelegate <NSObject>
- (void)unityAdsReady: (NSString *)placementId;
- (void)unityAdsDidError: (UnityAdsError)error withMessage: (NSString *)message;
- (void)unityAdsDidStart: (NSString *)placementId;
- (void)unityAdsDidFinish: (NSString *)placementId
withFinishState: (UnityAdsFinishState)state;
@end
Implement this delegate to handle various states of an ad. Implement it in your script to define logic for rewarded ads.
unityAdsReady
Removed in SDK version 4.0. For more information, refer to the deprecated API classes.
Specify logic for ad content being ready to display through a specified Ad Unit.
Parameter | Description |
---|---|
| The identifier for the Ad Unit that is ready. |
unityAdsDidError
Removed in SDK version 4.0. For more information, refer to the deprecated API classes.
Specify logic for ad content failing to display due to an error.
Parameter | Description |
---|---|
| The |
| A message associated with the error. |
unityAdsDidStart
Removed in SDK version 4.0. For more information, refer to the deprecated API classes.
Specify logic for the player triggering an ad to show.
Parameter | Description |
---|---|
| The identifier for the Ad Unit that is showing the ad. |
unityAdsDidFinish
Removed in SDK version 4.0. For more information, refer to the deprecated API classes.
Specify logic for the player watching the ad in its entirety.
Parameter | Description |
---|---|
| The identifier for the Ad Unit that finished showing. |
| The resulting user event of the ad showing. |
UADSBannerDelegate
@protocol UADSBannerViewDelegate <NSObject>
@optional
- (void)bannerViewDidLoad: (UADSBannerView *)bannerView;
- (void)bannerViewDidClick: (UADSBannerView *)bannerView;
- (void)bannerViewDidLeaveApplication: (UADSBannerView *)bannerView;
- (void)bannerViewDidError: (UADSBannerView *)bannerView error: (UADSBannerError *)error;
@end
This delegate provides callbacks from Unity Ads banner events.
bannerViewDidLoad
This callback fires when the banner successfully loaded ad content.
bannerViewDidClick
This callback fires when the user clicked the banner ad.
bannerViewDidLeaveApplication
This callback fires when the banner closed because the user quit the application.
bannerViewDidError
This callback fires when UnityAdsBanner encounters an error.
Parameter | Description |
---|---|
| The |
UADSBannerAdRefreshViewDelegate
Note: This delegate is deprecated and will be removed in a future major version release of the Unity Ads SDK.
@protocol UADSBannerAdRefreshViewDelegate <NSObject>
@optional
- (void)unityAdsRefreshBannerDidLoad: (UADSBannerAdRefreshView *)bannerAdRefreshView;
- (void)unityAdsRefreshBannerDidNoFill: (UADSBannerAdRefreshView *)bannerAdRefreshView;
- (void)unityAdsRefreshBannerDidShow: (UADSBannerAdRefreshView *)bannerAdRefreshView;
- (void)unityAdsRefreshBannerDidHide: (UADSBannerAdRefreshView *)bannerAdRefreshView;
- (void)unityAdsRefreshBannerDidClick: (UADSBannerAdRefreshView *)bannerAdRefreshView;
- (void)unityAdsRefreshBannerDidError: (UADSBannerAdRefreshView *)bannerAdRefreshView message: (NSString *)message;
@end
This delegate provides callbacks from Unity Ads refresh banner events.
unityAdsRefreshBannerDidLoad
Called when the banner is loaded and ready to be placed in the view hierarchy.
unityAdsRefreshBannerDidNoFill
Called when no ad content is available for the banner.
unityAdsRefreshBannerDidShow
Called when the banner is visible to the user.
unityAdsRefreshBannerDidHide
Called when the banner is hidden to the user.
unityAdsRefreshBannerDidClick
Called when the user clicked the banner ad.
unityAdsRefreshBannerDidError
Called when UnityAdsBanner
encounters an error.
Parameter | Description |
---|---|
| A message associated with the error. |