4. Call the Inference API
Configure the Airflux SDK to request an inference decision before displaying an interstitial ad. Based on the AI's response, you can decide whether to proceed with showing the ad. This process allows for smarter, more revenue-optimized ad delivery.

1. Set up the API Call and callbacks
Use the Airflux.requestInference() function with the SHOW_INTERSTITIAL_AD method to request a real-time ad decision. To ensure the AI makes an accurate decision, you must provide detailed contextual parameters and implement the appropriate callbacks.
Code Example
import Airflux
Airflux.requestInference(
AirfluxInference.SHOW_INTERSTITIAL_AD(
parameters: [
AirfluxParameter.AD_TYPE: "interstitial_ad",
AirfluxParameter.AD_PLACEMENT_ID: "placement_3",
AirfluxParameter.AD_PLACEMENT_TYPE: "static",
AirfluxParameter.AD_PLACEMENT_POSITION: "stage_start",
AirfluxParameter.STAGE: 10,
AirfluxParameter.STAGE_TYPE: "primary_stage",
AirfluxParameter.TOTAL_FINISHED_STAGE: 10,
AirfluxParameter.STAGE_RESULT: "success",
AirfluxParameter.AD_COOLDOWN_SECONDS: [
"rewarded_ad": 10,
"interstitial_ad": 20
],
AirfluxParameter.REWARD_ITEMS: [
"coin": 500,
"gem": 10
],
AirfluxParameter.FORCE_RESPONSE: [
"action": "showAd",
"parameters": [String: Any]()
]
],
onShowAd: {
// AI determined to show the ad. Implement your logic here.
print("AI decided to show ad.")
},
onSkipAd: {
// AI determined to skip the ad. Implement your logic here.
print("AI decided to skip ad.")
},
onDefaultAdPolicy: {
// Implement your internal logic to decide whether to show or skip the ad.
print("AI returned default policy. Implementing internal logic.")
},
onFailure: { error in
// Inference request failed. Implement your internal logic to handle the error
// and decide whether to show or skip the ad based on your game's policy.
print("Inference request failed: \(error.message). Falling back to default policy.")
}
)
)
#import <Airflux/Airflux.h>
[Airflux requestInference:[AirfluxInference SHOW_INTERSTITIAL_AD:@{
AirfluxParameter.AD_TYPE: @"interstitial_ad",
AirfluxParameter.AD_PLACEMENT_ID: @"placement_3",
AirfluxParameter.AD_PLACEMENT_TYPE: @"static",
AirfluxParameter.AD_PLACEMENT_POSITION: @"stage_start",
AirfluxParameter.STAGE_TYPE: @"primary_stage",
AirfluxParameter.STAGE: @(10),
AirfluxParameter.TOTAL_FINISHED_STAGE: @(10),
AirfluxParameter.STAGE_RESULT: @"success",
AirfluxParameter.AD_COOLDOWN_SECONDS: @{
@"rewarded_ad": @(10),
@"interstitial_ad": @(20)
},
AirfluxParameter.REWARD_ITEMS: @{
@"coin": @(500),
@"gem": @(10)
},
AirfluxParameter.FORCE_RESPONSE: @{
@"action": @"showAd",
@"parameters": @{}
}
} onShowAd:^{
// AI determined to show the ad. Implement your logic here.
NSLog(@"AI decided to show ad.");
} onSkipAd:^{
// AI determined to skip the ad. Implement your logic here.
NSLog(@"AI decided to skip ad.");
} onDefaultAdPolicy:^{
// Implement your internal logic to decide whether to show or skip the ad.
NSLog(@"AI returned default policy. Implementing internal logic.");
} onFailure:^(NSError * _Nonnull error) {
// Inference request failed. Implement your internal logic to handle the error
// and decide whether to show or skip the ad based on your game's policy.
NSLog(@"Inference request failed: %@. Falling back to default policy.", error.localizedDescription);
}]];Verification
2. Deploy the app
After completing sufficient QA and crash testing, deploy your gaming app. To ensure proper integration with Airflux, make sure the deployment follows the timeline coordinated with the Growth Manager.
Next steps
Congratulations! If you have completed the steps above, you are all set to optimize your in-game advertising with Airflux. Click here to learn how to receive your optimization results.
Frequently Asked Questions
Last updated

