Open
Description
Description
When trying to setup notifications in Firebase (with SwiftUI), I followed the guidelines and the app just crashes when trying to setup. I do not get output but a crash ending with:
#0 0x000000010151c2a8 in _dispatch_assert_queue_fail ()
#11 0x000000020dd04680 in _pthread_wqthread ()
Enqueued from com.apple.NSXPCConnection.m-user.com.apple.usernotifications.listener (Thread 3) Queue : com.apple.NSXPCConnection.m-user.com.apple.usernotifications.listener (serial)
#0 0x000000010575b1f0 in dispatch_async ()
#16 0x000000020dd02474 in start_wqthread ()
I'm using Swift 6 and SwiftUI. nonisolated
is required to make the program compile (both nonisolated
and nonisolated(unsafe)
crash the program).
Reproducing the issue
import Firebase
import FirebaseMessaging
import SwiftUI
private final class AppDelegate: NSObject, UIApplicationDelegate, MessagingDelegate, UNUserNotificationCenterDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
FirebaseApp.configure()
Messaging.messaging().delegate = self
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: { _, _ in }
)
application.registerForRemoteNotifications()
return true
}
nonisolated(unsafe) func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
Messaging.messaging().token { token, error in
if let error = error {
print("Error fetching FCM registration token: \(error)")
} else if let token = token {
print("FCM registration token: \(token)")
//self.fcmRegTokenMessage.text = "Remote FCM registration token: \(token)"
}
}
}
nonisolated(unsafe) func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
) {
completionHandler([.banner, .sound, .badge])
}
nonisolated(unsafe) func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
completionHandler()
}
}
@main
private struct MyApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) fileprivate var delegate
var body: some Scene {
WindowGroup {
}
}
}
Firebase SDK Version
11.9.0
Xcode Version
16.2
Installation Method
Swift Package Manager
Firebase Product(s)
In-App Messaging
Targeted Platforms
iOS
Relevant Log Output
If using Swift Package Manager, the project's Package.resolved
Expand Package.resolved
snippet
Replace this line with the contents of your Package.resolved.
If using CocoaPods, the project's Podfile.lock
Expand Podfile.lock
snippet
Replace this line with the contents of your Podfile.lock!