ToneSnap_FSX_Flutter/lib/global/app_lifecycle_reactor.dart
fengshengxiong caded892d9 1.新增瀑布流插页广告
2.新增增埋点
2024-08-14 13:56:43 +08:00

29 lines
919 B
Dart

// Author: fengshengxiong
// Date: 2024/6/25
// Description: 应用程序生命周期反应器
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'package:tone_snap/ads/interstitial_ad_manager.dart';
import 'package:tone_snap/data/enum/ad_scenes.dart';
class AppLifecycleReactor {
AppLifecycleReactor._();
static final AppLifecycleReactor _instance = AppLifecycleReactor._();
factory AppLifecycleReactor() {
return _instance;
}
void listenToAppStateChanges() {
AppStateEventNotifier.startListening();
AppStateEventNotifier.appStateStream.forEach((state) => _onAppStateChanged(state));
}
void _onAppStateChanged(AppState appState) {
// 如果应用程序正在恢复前台,尝试显示开屏广告
if (appState == AppState.foreground && !InterstitialAdManager().isShowingAd) {
InterstitialAdManager().showAdIfAvailable(AdScenes.hotLoading.name);
}
}
}