-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(Crash - ios) -[FLTAppStateNotifier handleDidEnterBackground] #1138
Comments
Hi @binSaed, thanks for flagging. I've escalated this to engineering to take a closer look. |
I have the same issue. Lot of crashes. :/ |
use this @Goodstuff4UonYT import 'dart:async';
import 'dart:io';
import 'package:flutter/widgets.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
// https://github.com/googleads/googleads-mobile-flutter/issues/1138
// AppStateEventNotifier from admob package currently crashes sometimes on iOS
// so we replace it with AppLifecycleListener from flutter package only in ios
// we keep using AppStateEventNotifier in android because AppLifecycleListener called when ads appear or when taking picture
// after GoogLeads teem fix this issue we will back to use AppStateEventNotifier
class AppStateListener {
static final AppStateListener _instance = AppStateListener._();
static AppStateListener get i => _instance;
StreamController<AppState>? _appStateController;
AppStateListener._() {
if (Platform.isAndroid) AppStateEventNotifier.startListening();
if (Platform.isIOS) {
_appStateController = StreamController<AppState>.broadcast();
AppLifecycleListener(
onStateChange: (event) {
if (event == AppLifecycleState.resumed) {
_appStateController!.add(AppState.foreground);
}
if (event == AppLifecycleState.paused) {
_appStateController!.add(AppState.background);
}
},
);
}
}
Stream<AppState> get appStateStream {
if (Platform.isAndroid) {
return AppStateEventNotifier.appStateStream;
} else {
return _appStateController!.stream;
}
}
Stream<AppState> get onResumed {
return appStateStream.where((event) => event == AppState.foreground);
}
Stream<AppState> get onBackground {
return appStateStream.where((event) => event == AppState.background);
}
}
AppStateListener.i.appStateStream.listen(
(AppState state) {},
);
|
@binSaed Thanks! :) |
Thanks for sharing @binSaed. With the resolution able to implemented without SDK intervention and confirmed, closing this out. Please see #1138 (comment) for a solution |
@malandr2 If you use the App Open Ads as described in the documentation, you have this high crash rate. What was sent in is just a workaround that comes with some disadvantages. Simply closing the issue is a mistake! |
Plugin Version
google_mobile_ads: ^5.1.0
[REQUIRED] Step 2: Describe the problem
Steps to Reproduce
Actual results:
Logs
Crashlytics
flutter doctor -v
The text was updated successfully, but these errors were encountered: