I've come across many questions like this on StackOverflow and Github, but I haven't found the answer.
I have an Apple development profile, and I've uploaded APNs Auth Key to Firebase.
I have enabled Background fetch, Remote notifications and Background processing, as well as Push Notifications in my xCode.
I have added this two pieces of code to AppDelegate.swift:
import Firebase
if FirebaseApp.app() == nil {
FirebaseApp.configure()
}
...
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
I have added this line to Info.plist:
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
I've also tried (not working as well):
key>FirebaseAppDelegateProxyEnabled</key>
<string>0</string>
I have followed the instructions from https://pub.dev/packages/firebase_messaging and I get notifications when my app is in the foreground (onMessage is executed). However, I get no notifications at all when it's in the background. I've tried everything I could find suggested, nothing works. I am really desperate at this point. It doesn't work for the simulator or the real device. Can this even work? If so, please help me get it to.