App-Open Ads
A full-screen ad displayed when the app is launched or foregrounded.
iOS
final class AppOpenAdManager: NSObject, ObservableObject, FuseFullScreenAdViewDelegate {
private let ad: FuseFullScreenAdView
init(code: String) {
ad = FuseFullScreenAdView(code: code)
ad.delegate = self
}
func showAd() {
ad.show()
}
func onEvent(adView: FuseFullScreenAdView, event: FuseAdViewEvent) {
print("Ad event: \(event)")
}
}
@main
struct iosApp: App {
@StateObject private var adManager = AppOpenAdManager(code: "<zone_code>")
var body: some Scene {
WindowGroup {
MainView()
// Display ad on app foreground with 1 second display timeout
.onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)) { _ in
adManager.showAd(timeout: 1)
}
}
}
}
For more examples, see the iOS example repository.
Android
class DemoApplication :
Application(),
Application.ActivityLifecycleCallbacks,
DefaultLifecycleObserver {
private var currentActivity: Activity? = null
private var ad = FuseFullScreenAdView(this, "<zone_code>").apply {
listener = object : FuseFullScreenAdViewListener {
override fun onEvent(
adView: FuseFullScreenAdView,
event: FuseAdViewEvent,
) {
println("Ad event: $event")
}
}
}
override fun onCreate() {
super<Application>.onCreate()
registerActivityLifecycleCallbacks(this)
ProcessLifecycleOwner.get().lifecycle.addObserver(this)
}
override fun onStart(owner: LifecycleOwner) {
super.onStart(owner)
// Show the ad (if available) when the app moves to foreground
currentActivity?.let {
ad?.show(it, 1000)
}
}
// ActivityLifecycleCallback methods
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {}
override fun onActivityStarted(activity: Activity) {
// Updating the currentActivity only when an ad is not showing
if (activity !is AdActivity) {
currentActivity = activity
}
}
override fun onActivityResumed(activity: Activity) {}
override fun onActivityPaused(activity: Activity) {}
override fun onActivityStopped(activity: Activity) {}
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}
override fun onActivityDestroyed(activity: Activity) {}
}
For more examples, see the Android example repository.
Flutter
App-open ads in Flutter follow the same pattern as interstitial ads. Create a FuseFullScreenAdView and call show() when the app enters the foreground. See the Interstitial section for the base implementation.
React Native
Use React Native’s AppState API to detect when the app returns to the foreground, then show the ad with a short timeout.
import React, { useEffect, useRef } from 'react';
import { AppState } from 'react-native';
import { FuseFullScreenAdView, FuseAdViewEvent } from '@publift/react-native-fuseapp';
function AppOpenAdManager() {
const adRef = useRef<FuseFullScreenAdView | null>(null);
const appState = useRef(AppState.currentState);
useEffect(() => {
const ad = new FuseFullScreenAdView({
code: '<zone_code>',
onEvent: (data) => {
console.log('Ad event:', data.event);
},
});
adRef.current = ad;
const subscription = AppState.addEventListener('change', async (nextAppState) => {
if (
appState.current.match(/inactive|background/) &&
nextAppState === 'active'
) {
await adRef.current?.show(1000).catch(() => {});
}
appState.current = nextAppState;
});
return () => {
subscription.remove();
ad.dispose();
};
}, []);
return null;
}