OneSignal-Flutter-SDK
OneSignal-Flutter-SDK copied to clipboard
[Bug]: Application crash on iOS when push message is received with app in background
What happened?
Hi, I am building my first integration of Onesignal on iOS. Android works nicely so far. I have a crash (see steps below) when a push is received. The app is monitored with Sentry and it catches nothing so I suspect it is something happening in native code or similar, before the dart main() is called
Steps to reproduce?
1. create flutter app
2. add onesignal package and do all the iOS configuration steps EXCEPT for the extension ones (i am good with simple text push messages)
3. compile
4. send a push message:
- if the app is in the foreground -> it works
- if the app is in background -> crash.
What did you expect to happen?
no crashes..
OneSignal Flutter SDK version
5.2.5 and 5.2.6
Which platform(s) are affected?
- [X] iOS
- [ ] Android
Relevant log output
No response
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
i also got the same problem, didn't find solution yet?
I solved using the hint in https://stackoverflow.com/questions/70812697/a-firebase-app-named-default-already-exists/71644195#71644195 but it seems a workaround and not a real fix....
Is this in my main file or in package files?
I was facing this issue, and when I checked what was causing it, it was Firebase initialization.
1:I added Firebase initialization to the native code:
import Flutter import UIKit import Firebase //add this
@main @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { FirebaseApp.configure() //add this GeneratedPluginRegistrant.register(with: self) return super.application(application, didFinishLaunchingWithOptions: launchOptions) } }
2: Change ios target deploys for 13.0: xcode -> Runner -> Build settings -> ios deployment target -> 13.0
3: And added GoogleService-Info.plist through Xcode.
From the OneSignal iOS SDK:
https://github.com/OneSignal/OneSignal-iOS-SDK/blob/7d12cc4fd55ee61b878508af9f1501e1933ce53d/iOS_SDK/OneSignalSDK/Source/OneSignal.m#L441-L445
https://github.com/OneSignal/OneSignal-iOS-SDK/blob/7d12cc4fd55ee61b878508af9f1501e1933ce53d/iOS_SDK/OneSignalSDK/Source/OneSignal.m#L528
The SDK checks if Firebase is present, and if so, it will try to send tracking events.
The problem is that if you have Firebase as a dependency, but never actually setup it, this will crash.
So basically there are three solutions:
- Remove the Firebase dependency.
- Properly setup Firebase
- The OneSignal iOS SDK has an option to disable this functionality.