-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Description
I have configured remote notifications for my cross-platform SwiftUI app, everything functions correctly and I'm receiving notifications on iOS devices but receive apns errors when launching on visionOS.
ERROR:
10.28.0 - [FirebaseMessaging][I-FCM023014] No aps-environment set. If testing on a device APNS is not correctly configured. Please recheck your provisioning profiles. If testing on a simulator this is fine since APNS doesn't work on the simulator.
I do successfully received the device token from fcm. These errors do not occur on iOS. I have also tested this on a clean project and had the same results.
Reproducing the issue
Using standing setup for a SwiftUI app will produce the errors when targeting visionOS
`import SwiftUI
import FirebaseCore
import FirebaseMessaging
class AppDelegate: NSObject, UIApplicationDelegate, MessagingDelegate, UNUserNotificationCenterDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
application.registerForRemoteNotifications()
registerForPushNotifications(application: application)
FirebaseApp.configure()
Messaging.messaging().delegate = self
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
let token = tokenParts.joined()
print("Device Token: \(token)")
Messaging.messaging().apnsToken = deviceToken
}
func registerForPushNotifications(application: UIApplication) {
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { granted, error in
if let error = error {
print("Failed to request authorization: \(error.localizedDescription)")
return
}
guard granted else { return }
DispatchQueue.main.async {
application.registerForRemoteNotifications()
}
}
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.banner, .badge, .sound])
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
completionHandler()
}
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
print("Token: \(fcmToken)")
}
}
@main
struct NotificationsApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
ContentView()
}
ImmersiveSpace(id: "ImmersiveSpace") {
ImmersiveView()
}
}
}`
Firebase SDK Version
10.28.0
Xcode Version
15.2
Installation Method
Swift Package Manager
Firebase Product(s)
Messaging
Targeted Platforms
iOS, visionOS
Relevant Log Output
10.28.0 - [FirebaseMessaging][I-FCM023014] No aps-environment set. If testing on a device APNS is not correctly configured. Please recheck your provisioning profiles. If testing on a simulator this is fine since APNS doesn't work on the simulator.
<Error>: 10.28.0 - [FirebaseMessaging][I-FCM023014] No aps-environment set. If testing on a device APNS is not correctly configured. Please recheck your provisioning profiles. If testing on a simulator this is fine since APNS doesn't work on the simulator.
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!