OneSignal-Flutter-SDK icon indicating copy to clipboard operation
OneSignal-Flutter-SDK copied to clipboard

[Bug]: Application crash on iOS when push message is received with app in background

Open nebis-software opened this issue 1 year ago • 5 comments
trafficstars

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

nebis-software avatar Nov 06 '24 15:11 nebis-software

i also got the same problem, didn't find solution yet?

octav8us avatar May 08 '25 10:05 octav8us

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....

nebis-software avatar May 08 '25 10:05 nebis-software

Is this in my main file or in package files?

octav8us avatar May 08 '25 17:05 octav8us

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.

nandohawkeye avatar Jul 28 '25 17:07 nandohawkeye

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:

  1. Remove the Firebase dependency.
  2. Properly setup Firebase
  3. The OneSignal iOS SDK has an option to disable this functionality.

miquelbeltran avatar Oct 08 '25 10:10 miquelbeltran