iOS
Adiz iOS¶
Adiz iOS is an advertising module for iOS provided on the Hive platform to make it easier to use the ad exposure features offered by AdMob. The types of ads provided by Adiz iOS are as follows.
- Interstitial Ads
- Banner Ads
- Native Ads
- Rewarded Ads
- Rewarded Interstitial Ads
- App Open Ads
To install and use Adiz iOS, please refer to the guide below in order.
Preparation¶
Set up the Adiz iOS development environment.
Installation¶
Add the GADApplicationIdentifier
key to the Info.plist file of your Xcode project and enter the AdMobId
value (in the format ca-app-pub-XXXXX~YYYYY) as the value for the key.
Additionally, for iOS 14 and above, refer to the Update your info.plist guide to add the SKAdNetwork
list to the Info.plist file.
Next, add the following content to the CocoaPods configuration (Podfile) of the project.
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/Com2uSPlatformCorp/HiveAdiz-iOS.git'
platform :ios, '12.0'
target 'UnityFramework' do
pod 'HiveAdiz', '2.1.0'
end
target 'Unity-iPhone' do
end
use_frameworks!
# fix for dyld issue in pods when using Project
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
# xcode 15 Toolchain Issue
xcconfig_path = config.base_configuration_reference.real_path
xcconfig = File.read(xcconfig_path)
xcconfig_mod = xcconfig.gsub(/DT_TOOLCHAIN_DIR/, "TOOLCHAIN_DIR")
File.open(xcconfig_path, "w") { |file| file << xcconfig_mod }
# end
config.build_settings["BUILD_LIBRARY_FOR_DISTRIBUTION"] = "YES"
if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 12.0
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
end
end
end
end
Apply the CocoaPod settings with $pod install
.
Test ad settings¶
Adiz can display test ads in 2 ways.
- Activate test mode: Only test ads issued by AdMob will be displayed
- Display ads after registering test devices: Display real ads for testing, ensuring no invalid traffic occurs, and proceed by registering devices that will display test ads
Test mode activation¶
In the development stage, the test mode is activated so that clicking on test ads does not charge advertisers. When the test mode is activated, only test ads will be displayed. In test mode, test ads will be displayed even without entering the AdMob ad key in the console. The test mode will be deactivated during commercial distribution.
There are two ways to activate test mode.
- After registering the test device in the Hive console, set it up as a demo ad (recommended):
Please refer to the Test Device Management section of the console guide. - Use the Adiz class's
setTestMode()
method:
Refer to the example code below.
Note
When not in test mode during the development stage, excessive clicks on ads may be considered invalid traffic, and your AdMob account may be reported, preventing ads from being displayed.
Using Adiz.setTestMode() method¶
Test device ad exposure¶
In the following situations, you need to register a test device to display test ads.
- Testing if the AdMob ad key registered in the console is working properly
- Writing a GDPR message and checking if the GDPR consent popup works well
- Running the ad inspector to analyze and debug ad requests
There are two ways to display ads on the test device.
-
After registering the test device in the Hive console, set it to Use Ad Unit ID (recommended):
Please refer to the Test Device Management section of the console guide. -
Use the Adiz class's
setTestDevice()
method:
Please refer to the example code below.
Note
If you conduct a test that exposes actual ads without registering a test device, it may be considered invalid traffic, resulting in your AdMob account being blocked and potentially preventing further ad exposure. By registering a test device, "Test Mode" or "Test Ad" (native ads) will be displayed during ad exposure. You must deactivate the test device during commercial distribution.
Banner, full-screen ads, or rewarded ads
Using Adiz.setTestDevice() method¶
To register a test device, you first need to check the test device ID. The test device ID (example: B74F6468-1516-467C-99AD-CC5973C5DB52
) can be verified in the following two ways.
- Check the Logcat logs after calling
Adiz.Initialize()
: - After calling
Adiz.Initialize()
, regardless of the ad type, callinitialize()
→load()
and check the Logcat logs:
After checking the test device ID, add the line Adiz.SetTestDevice(DEVICE_ID)
before executing Adiz.initialize
in the existing Hive Adiz initialization code. Enter the copied test device ID in DEVICE_ID
.
Ad inspector usage¶
The Ad Inspector is an in-app overlay tool that analyzes the process of requesting and displaying actual ads on a test device in real-time. It informs you of the time taken to load the ad and provides reasons for any failures in displaying the ad. You can also specify a particular ad network to check if the ads are being displayed correctly, and if there are issues, you can debug at the code level. All of this is done alongside the Ad Inspector UI. It is included in Google Mobile Ads SDK version 7.68.0 and above and can be used by calling AdizDeveloperTool.OpenAdInspector
.
To use the ad inspector, ad exposure on the test device must be set.
Adiz AppID settings¶
Set the Adiz AppID that you registered in the Hive console AppCenter. If not set, the Bundle ID will be used.
Hive Console server configuration¶
Setting up the Hive console server to use. The default is real
. Even if you use a production server, enabling test mode will only display test ads.
- Hive Test Console Server:
AdizZoneType.test
- Hive Sandbox Console Server:
AdizZoneType.sandbox
- Hive Production Console Server:
AdizZoneType.real
User-secific ad exposure¶
With the introduction of ATT (App Tracking Transparency) in iOS 14.5+, privacy protection has been strengthened. Accordingly, user-specific ads can only be displayed if the user agrees to activity tracking in the ATT consent popup. To maximize advertising revenue by displaying user-specific ads, you need to create an IDFA (Identifier for Advertisers) message.
AdMob Follow the IDFA message writing guide below on the dashboard to write and publish your messages.
- IDFA Implementation Guide
- IDFA Message Creation Guide
- Explanation about IDFA Messages and ATT Notifications
After writing and posting the IDFA message, set the user tracking access permissions. Follow the steps below to add the key to Info.plist.
- Select your project in the project navigator of the Xcode project window.
- Select your app in the TARGETS list.
- Click on the Info tab.
- Click on the Custom iOS Target Properties item in the Info tab.
- Right-click in the Custom iOS Target Properties list.
- Click on the Add Row menu.
- Enter NSUserTrackingUsageDescription in the Key field, and add the value specified in multilingual settings file > Base.Iproj folder > InfoPlist.strings in the Value field.
Next, write a message requesting permission approval from app users specified in the multilingual configuration file (General Settings > Access Permission Request Settings). If you do not enter a permission approval request popup message, the additional explanatory guide regarding the user access permissions in use will be missing, and the app will be rejected during the review process.
If you have completed up to this point, the ATT consent popup will be automatically displayed during Adiz initialization. When the user clicks "Allow" on the ATT consent popup, IDFA will be activated, and personalized ads will be displayed.
GDPR consent popup exposure (Europe, UK)¶
If your game targets Europe and the UK (EEA & UK), you must display a GDPR (General Data Protection Regulation) consent popup. The GDPR consent popup will only be displayed if the user's device IP address is from Europe and the UK (EEA & UK). Adiz supports the display of the GDPR consent popup through Google UMP (User Messaging Platform). After creating the GDPR message in the AdMob console, initialize Adiz to show the GDPR popup to users accessing from Europe and the UK.
Warning
When targeting regions outside of Europe and the UK, for example, if you are planning to provide services only domestically, you can skip the GDPR consent popup exposure (Europe, UK) step and proceed with initialization using the Adiz.initializeForNonGDPR()
method.
If you proceed with initialization using the Adiz.initialize()
method, you must create a GDPR message in the AdMob console for the Adiz initialization to proceed normally.
Writing GDPR message¶
Access the Google AdMob console to write a GDPR message. Before writing the GDPR message, please refer to the GDPR Message Writing Guide.
If you have written a GDPR message, the GDPR consent popup will automatically appear when Adiz is initialized.
Warning
If you are using the Hive SDK, you must run AuthV4.setup
after completing the Hive Adiz initialization. If the GDPR consent screen appears after displaying the ATT (App Tracking Transparency) consent notification, your app may be rejected during the Apple app review.
Implementing GDPR consent/withdrawal functionality¶
The items in the GDPR consent popup must provide a modification feature so that users can change their consent status at any time. For example, a user may initially not consent to GDPR but later wish to consent again to view personalized ads, or conversely, a user may have initially consented to GDPR but now wishes to withdraw their consent because they no longer want to provide personal information. To address these situations, app developers must implement functionality to re-consent to each item or withdraw existing consent. To implement the GDPR consent/withdrawal functionality, follow these steps.
- Implement a button UI in the app that can reopen the GDPR consent popup.
- When implementing Adiz initialization, call
isPrivacyOptionsRequired()
to display the button UI to users accessing from Europe and the UK, and do not display it otherwise. If a user from Europe or the UK clicks the button, callshowPrivacyOptionsForm
to reopen the GDPR consent popup. This allows users to modify their consent for GDPR details at any time by pressing a button like "Manage Options" in the app. TheshowPrivacyOptionsForm
below is a method implemented arbitrarily for illustration, and the developer can change the implementation as desired.
import HiveAdiz
func initialize(_ appId: String) {
// ...
// isPrivacyOptionsRequired is default false
targetViewController.showPrivacyFormButton.isEnabled = AdizConsentManager.isPrivacyOptionsRequired()
// HiveAdiz initialize
Adiz.initialize(targetViewController) { error, json in
// ...
// showPrivacyOptionsForm button enable check
targetViewController.showPrivacyFormButton.isEnabled = AdizConsentManager.isPrivacyOptionsRequired()
// ...
}
}
func showPrivacyOptionsForm(_ targetViewController: UIViewController) {
// Show GDPR Form
if AdizConsentManager.isPrivacyOptionsRequired() {
AdizConsentManager.showPrivacyOptionsForm(targetViewController) { error in
// No need to do any error handling.
}
}
}
#import <HiveAdiz/HiveAdiz-Swift.h>
- (void)initialize: (NSString *)appId {
// ...
// isPrivacyOptionsRequired is default false
targetViewController.showPrivacyFormButton.enabled = [AdizGDPRManager isPrivacyOptionsRequired];
// HiveAdiz initialize
[Adiz initialize: targetViewController handler:^(AdizError * error, NSDictionary<NSString *,id> * json) {
// ...
// showPrivacyOptionsForm button enable check
targetViewController.showPrivacyFormButton.enabled = [AdizConsentManager isPrivacyOptionsRequired];
// ...
}];
}
- (void)showPrivacyOptionsForm: (UIViewController*) targetViewController {
// Show GDPR Form
if ([AdizConsentManager isPrivacyOptionsRequired]) {
[AdizConsentManager showPrivacyOptionsForm: targetViewController handler:^(AdizError *error) {
// No need to do any error handling.
}];
}
}
Setting tags for users under GDPR consent age (TFUA)¶
You can set the tag for users under the age of consent (Tag For Under the Age of Consent, TFUA) when making advertising requests to treat users residing in the European Economic Area (EEA), the UK, and Switzerland as subjects of restricted data processing. For apps targeting children, you can use AdizConsentManager.SetUserPrivacySettings
to set that the user is under the age of consent. While there are some differences among European countries, GDPR defines under 16 as the age requiring parental consent. The underage consent setting must be configured before executing Adiz.initialize
.
Warning
Set the setTagForUnderAgeOfConsent
tag for under GDPR consent age and set setTagForChildDirectedTreatment
for COPPA children at the same time to true
, the COPPA children setting setTagForChildDirectedTreatment
will take precedence, so do not set them both to true
and use them simultaneously.
Note
When using Hive SDK v4 24.2.0 or higher together with Adiz 2.0.1 or higher, the user consent age set in Hive SDK is automatically applied, so there is no need to call AdizConsentManager.SetUserPrivacySettings
.
func initialize(_ appId: String) {
bool isTagForUnderAgeOfConsent = false // Change to true if underage
let privacySet = PrivacySettings.Builder()
.setTagForUnderAgeOfConsent(isTagForUnderAgeOfConsent)
AdizConsentManager.setUserPrivacySettings(privacySet.build())
// HiveAdiz initialize
Adiz.initialize(targetViewController) { error, json in
// ...
}
}
- (void)initialize: (NSString *)appId {
bool isTagForUnderAgeOfConsent = false; // Change to true if underage
PrivacySettingsBuilder* privacySet = [[PrivacySettingsBuilder alloc] init];
privacySet = [builder setTagForUnderAgeOfConsent: isTagForUnderAgeOfConsent];
[AdizConsentManager setUserPrivacySettings: [privacySet build]];
// HiveAdiz 초기화
[Adiz initialize: targetViewController handler:^(AdizError * error, NSDictionary<NSString *,id> * json) {
// ...
}];
}
GDPR test device setup¶
The GDPR consent popup is only displayed when the device's IP address is from Europe or the UK. During the development phase, the GDPR consent popup can be forcibly displayed regardless of the IP address to test the popup display, and to do this, you need to set up a GDPR test device. Follow the steps below to set up the GDPR test device.
- Initialize Adiz by initializing. This is an initialization to check the test device ID, and there is no need to write a GDPR consent message.
Check the debug log for a message that confirms the device ID. The message below is an example.
To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[B74F6468-1516-467C-99AD-CC5973C5DB52] Check the device ID in the message (example:
B74F6468-1516-467C-99AD-CC5973C5DB52
).- Copy the device ID.
- Add
Adiz.setTestDevice(DEVICE_ID)
before executingAdiz.initialize
in the existing Adiz initialization code. - Write the GDPR consent message and reinitialize Adiz to ensure that the GDPR consent popup appears correctly.
```swift
func initialize(_ appId: String) {
// ...
// Set TestDevice before Adiz.initialize. example @"B74F6468-1516-467C-99AD-CC5973C5DB52"
Adiz.setTestDevice("B74F6468-1516-467C-99AD-CC5973C5DB52")
// HiveAdiz initialize
Adiz.initialize(targetViewController) { error, json in
// ...
}
}
```
```obj
- (void)initialize: (NSString *)appId {
// ...
// Set TestDevice before Adiz.initialize. example @"B74F6468-1516-467C-99AD-CC5973C5DB52"
[Adiz setTestDevice: @"B74F6468-1516-467C-99AD-CC5973C5DB52"];
// HiveAdiz initialize
[Adiz initialize: targetViewController handler:^(AdizError * error, NSDictionary<NSString *,id> * json) {
// ...
}];
}
```
COPPA child-directed treatment tag setting¶
According to the Children's Online Privacy Protection Act (COPPA), app developers can specify whether Google should treat content as child-directed by setting the tag for child-directed treatment (tagForChildDirectedTreatment, TFCD) when making ad requests. If you want it to be treated as child-directed, you must call AdizConsentManager.SetUserPrivacySettings
before executing Adiz.initialize
. When using Adiz with the Hive SDK, the child-directed treatment tag is applied automatically, so no separate configuration is needed.
```swift
func initialize(_ appId: String) {
bool isTagForChildDirectedTreatment = false // Change to true if it is for children
let privacySet = PrivacySettings.Builder()
.setTagForChildDirectedTreatment(isTagForUnderAgeOfConsent)
AdizConsentManager.setUserPrivacySettings(privacySet.build())
// HiveAdiz initialize
Adiz.initialize(targetViewController) { error, json in
// ...
}
}
```
```obj
- (void)initialize: (NSString *)appId {
bool isTagForChildDirectedTreatment = false; // Change to true if it's for children
PrivacySettingsBuilder* privacySet = [[PrivacySettingsBuilder alloc] init];
privacySet = [builder setTagForChildDirectedTreatment: isTagForChildDirectedTreatment];
[AdizConsentManager setUserPrivacySettings: [privacySet build]];
// HiveAdiz initialize
[Adiz initialize: targetViewController handler:^(AdizError * error, NSDictionary<NSString *,id> * json) {
// ...
}];
}
```
Add ad mediation¶
Adiz can display ads using AdMob mediation. To add AdMob mediation, follow the steps below.
Adding AdMob Mediation¶
We will proceed with the integration of ad sources in the AdMob console. Follow the table below to proceed.
Adding Adiz adapter¶
Add dependencies to the CocoaPods Podfile.
# ...
$HIVE_ADIZ_VERSION = '2.1.0'
def adiz
pod 'HiveAdiz', $HIVE_ADIZ_VERSION
end
def adizAdapter
pod 'HiveAdizAdapterAppLovin', $HIVE_ADIZ_VERSION
pod 'HiveAdizAdapterPangle', $HIVE_ADIZ_VERSION
pod 'HiveAdizAdapterUnityAds', $HIVE_ADIZ_VERSION
pod 'HiveAdizAdapterMeta', $HIVE_ADIZ_VERSION
end
target 'MyGame-mobile' do
adiz
adizAdapter
end
# ...
To check if the Adiz adapter configuration has been applied correctly, run the app and check the configuration list on the Ad Inspector screen.
Adiz initialization¶
This is a mandatory step that must be performed before displaying ads of all types. By initializing Adiz, you will receive the ad key necessary for displaying ads. If you are in test mode, you will receive a test key. If you are using the Hive SDK, proceed with Adiz initialization after calling AuthV4.setup
.
Warning
If you are using GDPR settings, you must run AuthV4.setup
after completing the Hive Adiz initialization. If the GDPR consent screen appears after displaying the ATT (App Tracking Transparency) consent notification, the app may be rejected during Apple's app review.
import HiveAdiz
// Hive Adiz 초기화 중
Adiz.initialize(targetViewController) { error, json in
if error.isSuccess,
let responseList = json?["keys"] as? [[String:Any]] {
var interstitialKeyList = [String]()
var bannerKeyList = [String]()
var nativeKeyList = [String]()
var rewardedKeyList = [String]()
var rewardedInterstitialKeyList = [String]()
var appOpenKeyList = [String]()
for response in responseList {
if let isDefault = response["is_default"] as? Bool,
isDefault == false {
let hiveAdKey = response["key"] as? String ?? ""
let hiveForm = response["form"] as? String ?? ""
switch hiveForm {
case "interstitial": interstitialKeyList.append(hiveAdKey)
case "banner": bannerKeyList.append(hiveAdKey)
case "native": nativeKeyList.append(hiveAdKey)
case "rewarded": rewardedKeyList.append(hiveAdKey)
case "rewarded_interstitial": rewardedInterstitialKeyList.append(hiveAdKey)
case "app_open": appOpenKeyList.append(hiveAdKey)
default: break
}
}
}
print("interstitialKeyList \(interstitialKeyList)");
print("bannerKeyList \(bannerKeyList)");
print("nativeKeyList \(nativeKeyList)");
print("rewardedKeyList \(rewardedKeyList)");
print("rewardedInterstitialKeyList \(rewardedInterstitialKeyList)");
print("appOpenKeyList \(appOpenKeyList)");
}
}
#import <HiveAdiz/HiveAdiz-Swift.h>
// Initializing Hive Adiz
[Adiz initialize: targetViewController handler:^(AdizError * error, NSDictionary<NSString *,id> * json) {
if([error isSuccess] && json[@"keys"] != nil) {
NSArray* responseList = json[@"keys"];
NSMutableArray<NSString*> *interstitialKeyList = [[NSMutableArray alloc] init];
NSMutableArray<NSString*> *bannerKeyList = [[NSMutableArray alloc] init];
NSMutableArray<NSString*> *nativeKeyList = [[NSMutableArray alloc] init];
NSMutableArray<NSString*> *rewardedKeyList = [[NSMutableArray alloc] init];
NSMutableArray<NSString*> *rewardedInterstitialKeyList = [[NSMutableArray alloc] init];
NSMutableArray<NSString*> *appOpenKeyList = [[NSMutableArray alloc] init];
for (NSDictionary* response in responseList) {
// This is an example of setting up the list of ad keys (is_default = false) when you wants to put the ad key directly.
if (response[@"is_default"] != nil && [response[@"is_default"] boolValue] == false) {
NSString* hiveAdKey = response[@"key"];
NSString* hiveForm = response[@"form"];
if ([hiveForm isEqualToString: @"interstitial"]) {
[interstitialKeyList addObject: hiveAdKey];
} else if ([hiveForm isEqualToString: @"banner"]) {
[bannerKeyList addObject: hiveAdKey];
} else if ([hiveForm isEqualToString: @"native"]) {
[nativeKeyList addObject: hiveAdKey];
} else if ([hiveForm isEqualToString: @"rewarded"]) {
[rewardedKeyList addObject: hiveAdKey];
} else if ([hiveForm isEqualToString: @"rewarded_interstitial"]) {
[rewardedInterstitialKeyList addObject: hiveAdKey];
} else if ([hiveForm isEqualToString: @"app_open"]) {
[appOpenKeyList addObject: hiveAdKey];
}
}
}
NSLog(@"interstitialKeyList %@", interstitialKeyList);
NSLog(@"bannerKeyList %@", bannerKeyList);
NSLog(@"nativeKeyList %@", nativeKeyList);
NSLog(@"rewardedKeyList %@", rewardedKeyList);
NSLog(@"rewardedInterstitialKeyList %@", rewardedInterstitialKeyList);
NSLog(@"appOpenKeyList %@", appOpenKeyList);
}
}];
The JSON file received as a callback when initializing contains a list of advertisement keys. The list of advertisement keys has the following format.
{
"keys":[
{
"mediation_id":5,
"key":"ca-app-pub-3940256099942544/5354046379",
"form":"rewarded_interstitial",
"is_default":true,
"placement_id":"lobby01"
},
{
"mediation_id":4,
"key":"ca-app-pub-3940256099942544/5224354917",
"form":"rewarded",
"is_default":true,
"placement_id":"game02"
},
{
"mediation_id":3,
"key":"ca-app-pub-3940256099942544/2247696110",
"form":"native",
"is_default":true,
"placement_id":"event01"
},
{
"mediation_id":1,
"key":"ca-app-pub-3940256099942544/1033173712",
"form":"interstitial",
"is_default":true,
"placement_id":"mission01"
},
{
"mediation_id":2,
"key":"ca-app-pub-3940256099942544/6300978111",
"form":"banner",
"is_default":true,
"placement_id":"main01"
},
{
"mediation_id":6,
"key":"ca-app-pub-3940256099942544/9257395921",
"form":"app_open",
"is_default":true,
"placement_id":"appopen01"
}
]
}
When initializing in test mode, you will receive a list of test ad keys even if you have not registered the AdMob ad keys in the console. When initializing in production mode, you will receive the list of AdMob ad keys registered in the console.
For each type of advertisement (form
), one advertisement is used as the default advertisement (the advertisement with "is_default":true
). When the first advertisement of any type is registered, that advertisement becomes the default advertisement. The default advertisement does not require entering the advertisement key (hiveAdKey
) when creating an advertisement instance (initialize()
). To change the default advertisement, you must delete the existing default advertisement from the console and register a new advertisement.
Setting up ad callback listener¶
By implementing AdizListener
when creating each ad instance, you can receive callbacks based on changes in the ad status.
Name | Description | Required Implementation |
---|---|---|
onLoad() | Ad loaded successfully | O |
onFail(error: AdizError) | Failure (the reason for failure can be known by error.getCode() and error.getMessage() ) | O |
onShow() | Ad display success | O |
onClick() | Ad Click | O |
onPaidEvent(_ revenueData: AdRevenueData) | Received at the point of the paid event after ad exposure, where ad revenue information is conveyed | O |
onClose() | Ad End
| X |
onRewarded(_ rewardItem: RewardItem) | The point at which the user receives a reward after the ad exposure in reward-based ads (rewarded , rewarded interstitial ) | X |
import HiveAdiz
class TestAdizListener: AdizListener {
func onLoad() {
// Called when the ad is loaded.
// If the ad load is successful, you need to call the ad instance's .show() at the desired point to display the ad.
print("[\(delegateTypeName)] onLoad")
}
func onFail(_ error: AdizError) {
// Called if the ad load failed or the ad display failed for some other reason.
print("[\(delegateTypeName)] onFail: ")
print("(\(error.getCode())) \(error.getMessage() ?? "")")
}
func onShow() {
// Called when the ad is displayed.
print("[\(delegateTypeName)] onShow")
}
func onClick() {
// Called when the ad is clicked.
print("[\(delegateTypeName)] onClick")
}
func onPaidEvent(_ revenueData: AdRevenueData) {
// Called when the revenue for the ad is generated.
print("[\(delegateTypeName)] onPaidEvent: \(revenueData.getCurrency()) \(revenueData.getRevenue().description)")
var revenue = revenueData.getRevenue() // revenue when ad is exposed
var currency = revenueData.getCurrency() // currency code for revenue when ad is exposed
}
func onClose() {
// Called when the ad is closed.
// Banner, Native ads do not have an onClose callback.
print("[\(delegateTypeName)] onClose")
}
func onRewarded(_ rewardItem: RewardItem) {
// Called when a reward occurs for watching the ad in rewarded, rewarded interstitial ads.
print("[\(delegateTypeName)] onRewarded")
print("amount: \(rewardItem.getItemAmount()) type: \(rewardItem.getItemType())")
var itemType = rewardItem.getItemType() // Reward item type
var itemAmount = rewardItem.getItemAmount() // Reward item quantity }}
#import <HiveAdiz/HiveAdiz-Swift.h>
@interface TestAdizListener : NSObject<AdizListener>
@end
@implementation TestAdizListener
- (void) onLoad {
// Called when the ad is loaded.
// If the ad load is successful, you need to call the ad instance's .show() at the desired point to display the ad.
NSLog(@"[TestAdizListener] onLoad");
}
- (void) onFail:(AdizError *)error {
// Called if the ad load failed or the ad display failed for some other reason.
NSLog(@"[TestAdizListener] onFail: ");
NSLog(@"errorCode: %ld, errorMessage: %@", (long)[error getCode], [error getMessage]);
}
- (void) onShow {
// Called when the ad is displayed.
NSLog(@"[TestAdizListener] onShow");
}
- (void) onClick {
// Called when the ad is clicked.
NSLog(@"[TestAdizListener] onClick");
}
- (void) onPaidEvent:(AdRevenueData *)revenueData {
// Called when the revenue for the ad is generated.
NSLog(@"[TestAdizListener] onPaidEvent: %@ %f", [revenueData getCurrency], [revenueData getRevenue]);
double revenue = [revenueData getRevenue]; // revenue when ad is exposed
NSString* currency = [revenueData getCurrency]; // currency code for revenue when ad is exposed
}
- (void) onClose {
// Called when the ad is closed.
// Banner, Native ads do not have an onClose callback.
NSLog(@"[TestAdizListener] onClose");
}
- (void) onRewarded:(RewardItem *)rewardItem {
// Called when a reward occurs for watching the ad in rewarded, rewarded interstitial ads.
NSLog(@"[TestAdizListener] onRewarded");
NSLog(@"amount: %ld type: %@", (long)[rewardItem getItemAmount], [rewardItem getItemType]);
NSString* itemType = [rewardItem getItemType]; // Reward item type
NSInteger itemAmount = [rewardItem getItemAmount]; // Reward item type quantity
}
@end
Error codes¶
When receiving onFail()
from Adiz.Initialize
and AdizListener
, the AdizError
error codes and error messages are as follows.
Common Code¶
Number | Case | Explanation |
---|---|---|
0 | Success | Success |
Adiz error codes¶
Number | Case | Explanation |
---|---|---|
-1 | InvalidParam | Invalid parameter |
-2 | NotSupported | Not supported |
-3 | InProgress | Process in progress |
-4 | Network | Network error |
-5 | NeedInitialize | Initialization needed |
-6 | ResponseFail | Response failed |
-7 | Timeout | Network timeout |
-99 | Unknown | Unknown error |
Advertising platform error codes¶
Number | Case | Explanation |
---|---|---|
-101 | NeedLoad | Ad did not load |
-102 | NeedReload | Need to reload due to ad exposure time expiration |
-103 | NotEnoughInventory | Mediation response was successful, but no ads filled due to lack of inventory |
-104 | MissingAppId | AppID error for mediation request |
-105 | InternalNetworkError | Network-related error in mediation |
-106 | InvalidUnitId | Invalid Unit Id |
-107 | MediationNoFill | Mediation adapter failed to process ad request |
-108 | AlreadyLoaded | Already in a loaded state |
-109 | CannotRequestAds | Cannot request ads |
-201 | GdprConsentError | GDPR consent error |
-202 | IsNotPrivacyOptionsRequired | Cannot display GDPR consent popup or it is in a state where it does not need to be displayed |
Ad exposure and ad termination¶
To expose and terminate ads, follow the steps below.
- Create an ad instance in the ad class for each type of ad you want to display. If the ad you want to display is not a default ad, you must enter the ad key or placement ID obtained from initialization. If you do not enter the ad key (
hiveAdKey
) or placement ID (placementId
), a default ad instance will be created. The placement ID can be set in the Hive console, and for more details, refer to the Admob settings page in the console guide. - Load the ad you want to display (
load()
). - Show the loaded ad (
show()
). To show the ad again, you must callload()
again and then callshow()
. - To close the ad, call
destroy()
.
Interstitial advertising¶
This is a full-screen interstitial advertisement.
import UIKit
import HiveAdiz
class InitViewController: UIViewController {
// Create an interstitial ad instance.
var interstitialAd: AdizInterstitial?
func requestInitAd(hiveAdKey: String?) {
if let adKey = hiveAdKey,
adKey.count > 0 {
// Initialize AdizInterstitial Instance (ViewController, hiveAdKey, AdizListener)
self.interstitialAd = AdizInterstitial.initialize(self, hiveAdKey: adKey, adizListener: self)
}
else {
// Initialize Default AdizInterstitial Instance (ViewController, AdizListener)
self.interstitialAd = AdizInterstitial.initialize(self, adizListener: self)
}
}
func requestInitAdWithPlacementId(placementId: String?) {
if let placementId = placementId,
placementId.count > 0 {
// Initialize AdizInterstitial Instance (ViewController, placementId, AdizListener)
self.interstitialAd = AdizInterstitial.initializeWithPlacementId(self, placementId: placementId, adizListener: self)
}
else {
// Initialize Default AdizInterstitial Instance (ViewController, AdizListener)
self.interstitialAd = AdizInterstitial.initialize(self, adizListener: self)
}
}
func requestLoadAd() {
// Load AdizInterstitial
if let ad = self.interstitialAd,
ad.isInitialized() {
ad.load()
}
}
func requestShowAd() {
// Show AdizInterstitial
if let ad = self.interstitialAd,
ad.isLoaded() {
ad.show()
}
}
func requestDestroyAd() {
// Destroy AdizInterstitial
self.interstitialAd?.destroy()
self.interstitialAd = nil
}
}
extension InitViewController: AdizListener {
func onLoad() {
// requestShowAd()
}
func onFail(_ error: AdizError) {
}
func onShow() {
}
func onClick() {
}
func onPaidEvent(_ revenueData: AdRevenueData) {
}
func onClose() {
// requestDestroyAd()
}
}
#import <UIKit/UIKit.h>
#import <HiveAdiz/HiveAdiz-Swift.h>
@interface InitViewController : UIViewController<AdizListener>
@property (nonatomic, strong) AdizInterstitial* interstitialAd;
@end
@implementation InitViewController
- (void) requestInitAd: (NSString*)hiveAdKey {
if (hiveAdKey != nil && ![hiveAdKey isEqualToString:@""]) {
// Initialize AdizInterstitial Instance (ViewController, hiveAdKey, AdizListener)
// Create an interstitial ad instance.
self.interstitialAd = [AdizInterstitial initialize:self hiveAdKey:hiveAdKey adizListener:self];
}
else {
// Initialize Default AdizInterstitial Instance (ViewController, AdizListener)
self.interstitialAd = [AdizInterstitial initialize:self adizListener:self];
}
}
- (void) requestInitAdWithPlacementId: (NSString*)placementId {
if (placementId != nil && ![placementId isEqualToString:@""]) {
// Initialize AdizInterstitial Instance (ViewController, placementId, AdizListener)
// Create an interstitial ad instance.
self.interstitialAd = [AdizInterstitial initializeWithPlacementId:self placementId:placementId adizListener:self];
}
else {
// Initialize Default AdizInterstitial Instance (ViewController, AdizListener)
self.interstitialAd = [AdizInterstitial initialize:self adizListener:self];
}
}
- (void) requestLoadAd {
// Load AdizInterstitial
if (self.interstitialAd != nil && [self.interstitialAd isInitialized]) {
[self.interstitialAd load];
}
}
- (void) requestShowAd {
// Show AdizInterstitial
if (self.interstitialAd != nil && [self.interstitialAd isLoaded]) {
[self.interstitialAd show];
}
}
- (void) requestDestroyAd {
// Destroy AdizInterstitial
if (self.interstitialAd != nil) {
[self.interstitialAd destroy];
self.interstitialAd = nil;
}
}
#pragma mark - AdizListener
- (void) onLoad {
// [self requestShowAd];
}
- (void) onFail:(AdizError *)error {
}
- (void) onShow {
}
- (void) onClick {
}
- (void) onPaidEvent:(AdRevenueData *)revenueData {
}
- (void) onClose {
// [self requestDestroyAd];
}
@end
Banner advertising¶
This is a banner advertisement that displays a banner of a specific size. The banner advertisement does not receive the onClose()
callback. Therefore, you need to call destroy()
from another location to terminate the advertisement.
BannerSize
follows the standard banner size.
Size Points (Width x Height) | Description | Supported Devices | BannerSize Constant |
---|---|---|---|
320x50 | Banner | Mobile Phones and Tablets | BannerSize.normal |
320x100 | Large Banner | Mobile Phones and Tablets | BannerSize.medium |
300x250 | IAB Medium Rectangle | Mobile Phones and Tablets | BannerSize.large |
468 x 60 | IAB Full Size Banner | Tablets | BannerSize.full |
PositionType
is either the topmost or the bottommost. The default value is the bottommost.
Alignment | Description | PositionType Constant |
---|---|---|
Top Alignment | Specifies alignment at the top of the screen based on SafeArea | PositionType.top |
Bottom Alignment (default) | Specifies alignment at the bottom of the screen based on SafeArea | PositionType.bottom |
import UIKit
import HiveAdiz
class BannerViewController: UIViewController {
// Create AdizBanner Instance
// Create an banner ad instance.
var bannerAd: AdizBanner?
func requestInitAd(hiveAdKey: String?) { // Set banner size
var bannerSize: BannerSize = .normal
if let adKey = hiveAdKey,
adKey.count > 0 {
// Initialize AdizBanner Instance (ViewController, hiveAdKey, BannerSize, AdizListener)
self.bannerAd = AdizBanner.initialize(self, hiveAdKey: adKey, size: bannerSize, adizListener: self)
}
else {
// Initialize Default AdizBanner Instance (ViewController, BannerSize, AdizListener)
self.bannerAd = AdizBanner.initialize(self, size: bannerSize, adizListener: self)
}
}
func requestInitAdWithPlacementId(placementId: String?) { // Set banner size
var bannerSize: BannerSize = .normal
if let placementId = placementId,
placementId.count > 0 {
// Initialize AdizBanner Instance (ViewController, placementId, BannerSize, AdizListener)
self.bannerAd = AdizBanner.initializeWithPlacementId(self, placementId: placementId, size: bannerSize, adizListener: self)
}
else {
// Initialize Default AdizBanner Instance (ViewController, BannerSize, AdizListener)
self.bannerAd = AdizBanner.initialize(self, size: bannerSize, adizListener: self)
}
}
func requestLoadAd() {
// Load AdizBanner
if let ad = self.bannerAd,
ad.isInitialized() {
ad.load()
}
}
func requestShowAd() {
// Set position type
var position: PositionType = .top
// Show AdizBanner
if let ad = self.bannerAd,
ad.isLoaded() {
ad.show(position)
}
}
func requestDestroyAd() {
// Destroy AdizBanner
self.bannerAd?.destroy()
self.bannerAd = nil
}
}
extension BannerViewController: AdizListener {
func onLoad() {
// requestShowAd()
}
func onFail(_ error: AdizError) {
}
func onShow() {
}
func onClick() {
}
func onPaidEvent(_ revenueData: AdRevenueData) {
}
}
#import <UIKit/UIKit.h>
#import <HiveAdiz/HiveAdiz-Swift.h>
@interface BannerViewController : UIViewController<AdizListener>
@property (nonatomic, strong) AdizBanner* bannerAd;
@end
@implementation BannerViewController
- (void) requestInitAd: (NSString*)hiveAdKey {
// Set banner size
BannerSize bannerSize = BannerSizeNormal;
if (hiveAdKey != nil && ![hiveAdKey isEqualToString:@""]) {
// Initialize AdizBanner Instance (ViewController, hiveAdKey, BannerSize, AdizListener)
self.bannerAd = [AdizBanner initialize:self hiveAdKey:hiveAdKey size: bannerSize adizListener:self];
} else {
// Initialize Default AdizBanner Instance (ViewController, BannerSize, AdizListener)
self.bannerAd = [AdizBanner initialize:self size:bannerSize adizListener:self];
}
}
- (void) requestInitAdWithPlacementId: (NSString*)placementId {
// Set banner size
BannerSize bannerSize = BannerSizeNormal;
if (placementId != nil && ![placementId isEqualToString:@""]) {
// Initialize AdizBanner Instance (ViewController, placementId, BannerSize, AdizListener)
self.bannerAd = [AdizBanner initializeWithPlacementId:self placementId:placementId size: bannerSize adizListener:self];
} else {
// Initialize Default AdizBanner Instance (ViewController, BannerSize, AdizListener)
self.bannerAd = [AdizBanner initialize:self size:bannerSize adizListener:self];
}
}
- (void) requestLoadAd {
// Load AdizBanner
if (self.bannerAd != nil && [self.bannerAd isInitialized]) {
[self.bannerAd load];
}
}
- (void) requestShowAd {
// Set position type
PositionType position = PositionTypeTop;
// Show AdizBanner
if (self.bannerAd != nil && [self.bannerAd isLoaded]) {
[self.bannerAd show: position];
}
}
- (void) requestDestroyAd {
// Destroy AdizBanner
if (self.bannerAd != nil) {
[self.bannerAd destroy];
self.bannerAd = nil;
}
}
#pragma mark - AdizListener
- (void) onLoad {
// [self requestShowAd];
}
- (void) onFail:(AdizError *)error {
}
- (void) onShow {
}
- (void) onClick {
}
- (void) onPaidEvent:(AdRevenueData *)revenueData {
}
@end
Native advertising¶
This is a native advertisement that exposes a native template of a specific size. Native ads are optimized for vertical screens, so it is recommended to use them in vertical games (portrait screen games). Native ads do not receive the onClose()
callback. Therefore, you need to call destroy()
from another location to close the ad.
The current template supports small
or medium
sizes.
Size Points (Width x Height) | Template | Alignment | BannerSize Constant |
---|---|---|---|
355x91 (Aspect Ratio Adjusted) | small size | Top / Bottom | BannerSize.normal |
355x370 (Aspect Ratio Adjusted) | medium size | Center (Fixed) | BannerSize.medium, BannerSize.large, BannerSize.full |
In the small
template, PositionType
is either top or bottom, with the default being bottom.
Alignment | Description | PositionType Constant |
---|---|---|
Top Alignment | Specifies alignment at the top of the screen | PositionType.top |
Bottom Alignment (default) | Specifies alignment at the bottom of the screen | PositionType.bottom |
The medium
template does not allow for alignment selection and uses center alignment by default.
import UIKit
import HiveAdiz
class NativeViewController: UIViewController {
// Create AdizNative Instance
var nativeAd: AdizNative?
func requestInitAd(hiveAdKey: String?) {
// Set banner size
var bannerSize: BannerSize = .normal
if let adKey = hiveAdKey,
adKey.count > 0 {
// Initialize AdizNative Instance (ViewController, hiveAdKey, BannerSize, AdizListener)
self.nativeAd = AdizNative.initialize(self, hiveAdKey: adKey, size: bannerSize, adizListener: self)
}
else {
// Initialize Default AdizNative Instance (ViewController, BannerSize, AdizListener)
self.nativeAd = AdizNative.initialize(self, size: bannerSize, adizListener: self)
}
}
func requestInitAdWithPlacementId(placementId: String?) {
// Set banner size
var bannerSize: BannerSize = .normal
if let placementId = placementId,
placementId.count > 0 {
// Initialize AdizNative Instance (ViewController, placementId, BannerSize, AdizListener)
self.nativeAd = AdizNative.initializeWithPlacementId(self, placementId: placementId, size: bannerSize, adizListener: self)
}
else {
// Initialize Default AdizNative Instance (ViewController, BannerSize, AdizListener)
self.nativeAd = AdizNative.initialize(self, size: bannerSize, adizListener: self)
}
}
func requestLoadAd() {
// Load AdizNative
if let ad = self.nativeAd,
ad.isInitialized() {
ad.load()
}
}
func requestShowAd() {
// Set position type
var position: PositionType = .top
// Show AdizNative
if let ad = self.nativeAd,
ad.isLoaded() {
ad.show(position)
}
}
func requestDestroyAd() {
// Destroy AdizNative
self.nativeAd?.destroy()
self.nativeAd = nil
}
}
extension NativeViewController: AdizListener {
func onLoad() {
// requestShowAd()
}
func onFail(_ error: AdizError) {
}
func onShow() {
}
func onClick() {
}
func onPaidEvent(_ revenueData: AdRevenueData) {
}
}
#import <UIKit/UIKit.h>
#import <HiveAdiz/HiveAdiz-Swift.h>
@interface NativeViewController : UIViewController<AdizListener>
@property (nonatomic, strong) AdizNative* nativeAd;
@end
@implementation NativeViewController
- (void) requestInitAd: (NSString*)hiveAdKey {
// Set banner size
BannerSize bannerSize = BannerSizeNormal;
if (hiveAdKey != nil && ![hiveAdKey isEqualToString:@""]) {
// Initialize AdizNative Instance (ViewController, hiveAdKey, BannerSize, AdizListener)
self.nativeAd = [AdizNative initialize:self hiveAdKey:hiveAdKey size: bannerSize adizListener:self];
}
else {
// Initialize Default AdizNative Instance (ViewController, BannerSize, AdizListener)
self.nativeAd = [AdizNative initialize:self size:bannerSize adizListener:self];
}
}
- (void) requestInitAdWithPlacementId: (NSString*)placementId {
// Set banner size
BannerSize bannerSize = BannerSizeNormal;
if (placementId != nil && ![placementId isEqualToString:@""]) {
// Initialize AdizNative Instance (ViewController, placementId, BannerSize, AdizListener)
self.nativeAd = [AdizNative initializeWithPlacementId:self placementId:placementId size: bannerSize adizListener:self];
}
else {
// Initialize Default AdizNative Instance (ViewController, BannerSize, AdizListener)
self.nativeAd = [AdizNative initialize:self size:bannerSize adizListener:self];
}
}
- (void) requestLoadAd {
// Load AdizNative
if (self.nativeAd != nil && [self.nativeAd isInitialized]) {
[self.nativeAd load];
}
}
- (void) requestShowAd {
// Set position type
PositionType position = PositionTypeTop;
// Show AdizNative
if (self.nativeAd != nil && [self.nativeAd isLoaded]) {
[self.nativeAd show: position];
}
}
- (void) requestDestroyAd {
// Destroy AdizNative
if (self.nativeAd != nil) {
[self.nativeAd destroy];
self.nativeAd = nil;
}
}
#pragma mark - AdizListener
- (void) onLoad {
// [self requestShowAd];
}
- (void) onFail:(AdizError *)error {
}
- (void) onShow {
}
- (void) onClick {
}
- (void) onPaidEvent:(AdRevenueData *)revenueData {
}
@end
Rewarded ads¶
This is a rewarded ad where users receive rewards for watching the ad for a certain period of time. Once the reward is granted, the reward item information is received through the onRewarded()
callback.
import UIKit
import HiveAdiz
class RewardViewController: UIViewController {
// Create AdizRewarded Instance
var rewardAd: AdizRewarded?
func requestInitAd(hiveAdKey: String?) {
if let adKey = hiveAdKey,
adKey.count > 0 {
// Initialize AdizRewarded Instance (ViewController, hiveAdKey, AdizListener)
self.rewardAd = AdizRewarded.initialize(self, hiveAdKey: adKey, adizListener: self)
}
else {
// Initialize Default AdizRewarded Instance (ViewController, AdizListener)
self.rewardAd = AdizRewarded.initialize(self, adizListener: self)
}
}
func requestInitAdWithPlacementId(placementId: String?) {
if let placementId = placementId,
placementId.count > 0 {
// Initialize AdizRewarded Instance (ViewController, placementId, AdizListener)
self.rewardAd = AdizRewarded.initializeWithPlacementId(self, placementId: placementId, adizListener: self)
}
else {
// Initialize Default AdizRewarded Instance (ViewController, AdizListener)
self.rewardAd = AdizRewarded.initialize(self, adizListener: self)
}
}
func requestLoadAd() {
// Load AdizRewarded
if let ad = self.rewardAd,
ad.isInitialized() {
ad.load()
}
}
func requestShowAd() {
// Show AdizRewarded
if let ad = self.rewardAd,
ad.isLoaded() {
ad.show()
}
}
func requestDestroyAd() {
// Destroy AdizRewarded
self.rewardAd?.destroy()
self.rewardAd = nil
}
}
extension RewardViewController: AdizListener {
func onLoad() {
// requestShowAd()
}
func onFail(_ error: AdizError) {
}
func onShow() {
}
func onClick() {
}
func onPaidEvent(_ revenueData: AdRevenueData) {
}
func onClose() {
// requestDestroyAd()
}
func onRewarded(_ rewardItem: RewardItem) {
}
}
#import <UIKit/UIKit.h>
#import <HiveAdiz/HiveAdiz-Swift.h>
@interface RewardedViewController : UIViewController<AdizListener>
@property (nonatomic, strong) AdizRewarded* rewardedAd;
@end
@implementation RewardedViewController
- (void) requestInitAd: (NSString*)hiveAdKey {
if (hiveAdKey != nil && ![hiveAdKey isEqualToString:@""]) {
// Initialize AdizRewarded Instance (ViewController, hiveAdKey, AdizListener)
self.rewardedAd = [AdizRewarded initialize:self hiveAdKey:hiveAdKey adizListener:self];
}
else {
// Initialize Default AdizRewarded Instance (ViewController, AdizListener)
self.rewardedAd = [AdizRewarded initialize:self adizListener:self];
}
}
- (void) requestInitAdWithPlacementId: (NSString*)placementId {
if (placementId != nil && ![placementId isEqualToString:@""]) {
// Initialize AdizRewarded Instance (ViewController, placementId, AdizListener)
self.rewardedAd = [AdizRewarded initializeWithPlacementId:self placementId:placementId adizListener:self];
}
else {
// Initialize Default AdizRewarded Instance (ViewController, AdizListener)
self.rewardedAd = [AdizRewarded initialize:self adizListener:self];
}
}
- (void) requestLoadAd {
// Load AdizRewarded
if (self.rewardedAd != nil && [self.rewardedAd isInitialized]) {
[self.rewardedAd load];
}
}
- (void) requestShowAd {
// Show AdizRewarded
if (self.rewardedAd != nil && [self.rewardedAd isLoaded]) {
[self.rewardedAd show];
}
}
- (void) requestDestroyAd {
// Destroy AdizRewarded
if (self.rewardedAd != nil) {
[self.rewardedAd destroy];
self.rewardedAd = nil;
}
}
#pragma mark - AdizListener
- (void) onLoad {
// [self requestShowAd];
}
- (void) onFail:(AdizError *)error {
}
- (void) onShow {
}
- (void) onClick {
}
- (void) onPaidEvent:(AdRevenueData *)revenueData {
}
- (void) onClose {
// [self requestDestroyAd];
}
- (void) onRewarded:(RewardItem *)rewardItem {
}
@end
Rewarded interstitial ads¶
This is a rewarded interstitial ad where users receive rewards for watching the ad for a certain amount of time. Once the reward is granted, the reward item information is received through the onRewarded()
callback.
import UIKit
import HiveAdiz
class RewardInterstitialViewController: UIViewController {
// Create AdizRewardedInterstitial Instance
var rewardInterstitialAd: AdizRewardedInterstitial?
func requestInitAd(hiveAdKey: String?) {
if let adKey = hiveAdKey,
adKey.count > 0 {
// Initialize AdizRewardedInterstitial Instance (ViewController, hiveAdKey, AdizListener)
self.rewardInterstitialAd = AdizRewardedInterstitial.initialize(self, hiveAdKey: adKey, adizListener: self)
}
else {
// Initialize Default AdizRewardedInterstitial Instance (ViewController, AdizListener)
self.rewardInterstitialAd = AdizRewardedInterstitial.initialize(self, adizListener: self)
}
}
func requestInitAdWithPlacementId(placementId: String?) {
if let placementId = placementId,
placementId.count > 0 {
// Initialize AdizRewardedInterstitial Instance (ViewController, placementId, AdizListener)
self.rewardInterstitialAd = AdizRewardedInterstitial.initializeWithPlacementId(self, placementId: placementId, adizListener: self)
}
else {
// Initialize Default AdizRewardedInterstitial Instance (ViewController, AdizListener)
self.rewardInterstitialAd = AdizRewardedInterstitial.initialize(self, adizListener: self)
}
}
func requestLoadAd() {
// Load AdizRewardedInterstitial
if let ad = self.rewardInterstitialAd,
ad.isInitialized() {
ad.load()
}
}
func requestShowAd() {
// Show AdizRewardedInterstitial
if let ad = self.rewardInterstitialAd,
ad.isLoaded() {
ad.show()
}
}
func requestDestroyAd() {
// Destroy AdizRewardedInterstitial
self.rewardInterstitialAd?.destroy()
self.rewardInterstitialAd = nil
}
}
extension RewardInterstitialViewController: AdizListener {
func onLoad() {
// requestShowAd()
}
func onFail(_ error: AdizError) {
}
func onShow() {
}
func onClick() {
}
func onPaidEvent(_ revenueData: AdRevenueData) {
}
func onClose() {
// requestDestroyAd()
}
func onRewarded(_ rewardItem: RewardItem) {
}
}
#import <UIKit/UIKit.h>
#import <HiveAdiz/HiveAdiz-Swift.h>
@interface RewardedInterstitialViewController : UIViewController<AdizListener>
@property (nonatomic, strong) AdizRewardedInterstitial* rewardedInterstitialAd;
@end
@implementation RewardedInterstitialViewController
- (void) requestInitAd: (NSString*)hiveAdKey {
if (hiveAdKey != nil && ![hiveAdKey isEqualToString:@""]) {
// Initialize AdizRewardedInterstitial Instance (ViewController, hiveAdKey, AdizListener)
self.rewardedInterstitialAd = [AdizRewardedInterstitial initialize:self hiveAdKey:hiveAdKey adizListener:self];
}
else {
// Initialize Default AdizRewardedInterstitial Instance (ViewController, AdizListener)
self.rewardedInterstitialAd = [AdizRewardedInterstitial initialize:self adizListener:self];
}
}
- (void) requestInitAdWithPlacementId: (NSString*)placementId {
if (placementId != nil && ![placementId isEqualToString:@""]) {
// Initialize AdizRewardedInterstitial Instance (ViewController, placementId, AdizListener)
self.rewardedInterstitialAd = [AdizRewardedInterstitial initializeWithPlacementId:self placementId:placementId adizListener:self];
}
else {
// Initialize Default AdizRewardedInterstitial Instance (ViewController, AdizListener)
self.rewardedInterstitialAd = [AdizRewardedInterstitial initialize:self adizListener:self];
}
}
- (void) requestLoadAd {
// Load AdizRewardedInterstitial
if (self.rewardedInterstitialAd != nil && [self.rewardedInterstitialAd isInitialized]) {
[self.rewardedInterstitialAd load];
}
}
- (void) requestShowAd {
// Show AdizRewardedInterstitial
if (self.rewardedInterstitialAd != nil && [self.rewardedInterstitialAd isLoaded]) {
[self.rewardedInterstitialAd show];
}
}
- (void) requestDestroyAd {
// Destroy AdizRewardedInterstitial
if (self.rewardedInterstitialAd != nil) {
[self.rewardedInterstitialAd destroy];
self.rewardedInterstitialAd = nil;
}
}
#pragma mark - AdizListener
- (void) onLoad {
// [self requestShowAd];
}
- (void) onFail:(AdizError *)error {
}
- (void) onShow {
}
- (void) onClick {
}
- (void) onPaidEvent:(AdRevenueData *)revenueData {
}
- (void) onClose {
// [self requestDestroyAd];
}
- (void) onRewarded:(RewardItem *)rewardItem {
}
@end
App opening ads (AppOpen)¶
This is an app opening ad that displays a pre-loaded (load()
) ad when the app state changes from the background to the foreground. If show()
is called after 3 hours have passed since the ad was loaded, the ad will automatically reload and then be displayed. Once an ad has been displayed at least once, it will not reload automatically.
import UIKit
import HiveAdiz
class AppOpenViewController: UIViewController {
// Create AdizAppOpen Instance
var appOpenAd: AdizAppOpen?
func requestInitAd(hiveAdKey: String?) {
if let adKey = hiveAdKey,
adKey.count > 0 {
// Initialize AdizAppOpen Instance (ViewController, hiveAdKey, AdizListener)
self.appOpenAd = AdizAppOpen.initialize(self, hiveAdKey: adKey, adizListener: self)
}
else {
// Initialize Default AdizAppOpen Instance (ViewController, AdizListener)
self.appOpenAd = AdizAppOpen.initialize(self, adizListener: self)
}
}
func requestInitAdWithPlacementId(placementId: String?) {
if let placementId = placementId,
placementId.count > 0 {
// Initialize AdizAppOpen Instance (ViewController, placementId, AdizListener)
self.appOpenAd = AdizAppOpen.initializeWithPlacementId(self, placementId: placementId, adizListener: self)
}
else {
// Initialize Default AdizAppOpen Instance (ViewController, AdizListener)
self.appOpenAd = AdizAppOpen.initialize(self, adizListener: self)
}
}
func requestLoadAd() {
// Load AdizAppOpen
if let ad = self.appOpenAd,
ad.isInitialized() {
ad.load()
}
}
func requestShowAd() {
print("[appOpenAd] appOpenAd don't request Show")
}
func requestDestroyAd() {
// Destroy AdizAppOpen
self.appOpenAd?.destroy()
self.appOpenAd = nil
}
}
extension AppOpenViewController: AdizListener {
func onLoad() {
}
func onFail(_ error: AdizError) {
}
func onShow() {
}
func onClick() {
}
func onPaidEvent(_ revenueData: AdRevenueData) {
}
func onClose() {
// requestDestroyAd()
}
}
#import <UIKit/UIKit.h>
#import <HiveAdiz/HiveAdiz-Swift.h>
@interface AppOpenViewController : UIViewController<AdizListener>
@property (nonatomic, strong) AdizAppOpen* appOpenAd;
@end
@implementation AppOpenViewController
- (void) requestInitAd: (NSString*)hiveAdKey {
if (hiveAdKey != nil && ![hiveAdKey isEqualToString:@""]) {
// Initialize AdizAppOpen Instance (ViewController, hiveAdKey, AdizListener)
self.appOpenAd = [AdizAppOpen initialize:self hiveAdKey:hiveAdKey adizListener:self];
}
else {
// Initialize Default AdizAppOpen Instance (ViewController, AdizListener)
self.appOpenAd = [AdizAppOpen initialize:self adizListener:self];
}
}
- (void) requestInitAdWithPlacementId: (NSString*)placementId {
if (placementId != nil && ![placementId isEqualToString:@""]) {
// Initialize AdizAppOpen Instance (ViewController, placementId, AdizListener)
self.appOpenAd = [AdizAppOpen initializeWithPlacementId:self placementId:placementId adizListener:self];
}
else {
// Initialize Default AdizAppOpen Instance (ViewController, AdizListener)
self.appOpenAd = [AdizAppOpen initialize:self adizListener:self];
}
}
- (void) requestLoadAd {
// Load AdizAppOpen
if (self.appOpenAd != nil && [self.appOpenAd isInitialized]) {
[self.appOpenAd load];
}
}
- (void) requestShowAd {
NSLog(@"[appOpenAd] appOpenAd don't request Show");
}
- (void) requestDestroyAd {
// Destroy AdizAppOpen
if (self.appOpenAd != nil) {
[self.appOpenAd destroy];
self.appOpenAd = nil;
}
}
#pragma mark - AdizListener
- (void) onLoad {
}
- (void) onFail:(AdizError *)error {
}
- (void) onShow {
}
- (void) onClick {
}
- (void) onPaidEvent:(AdRevenueData *)revenueData {
}
- (void) onClose {
// [self requestDestroyAd];
}
@end