Repository: firebase/firebase-ios-sdk (language: cpp)

Issue:
Firebase Cloud Messaging not working with visionOS
### 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

```shell
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

<!--- Look below for instructions on how to share your Package.resolved. --->

<details>
<summary>Expand <code>Package.resolved</code> snippet</summary>
<br>

```json

Replace this line with the contents of your Package.resolved.

```

</details>


### If using CocoaPods, the project's Podfile.lock

<!--- Look below for instructions on how to share your Podfile.lock. --->

<details>
<summary>Expand <code>Podfile.lock</code> snippet</summary>
<br>

```yml

Replace this line with the contents of your Podfile.lock!

```

</details>



Discussion / hints:
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

Fix patch:
diff --git a/FirebaseMessaging/CHANGELOG.md b/FirebaseMessaging/CHANGELOG.md
index 29aa94a6057..d04f3da27c2 100644
--- a/FirebaseMessaging/CHANGELOG.md
+++ b/FirebaseMessaging/CHANGELOG.md
@@ -1,3 +1,6 @@
+# Unreleased
+- [fixed] Fixed the APS Environment key on visionOS. (#13173)
+
 # 10.29.0
 - [fixed] Renamed "initWithFileName" internal method that was causing submission issues for some
   users. (#13134).
diff --git a/FirebaseMessaging/Sources/FIRMessagingUtilities.m b/FirebaseMessaging/Sources/FIRMessagingUtilities.m
index 2d9bddb5187..212cdf7208d 100644
--- a/FirebaseMessaging/Sources/FIRMessagingUtilities.m
+++ b/FirebaseMessaging/Sources/FIRMessagingUtilities.m
@@ -28,12 +28,16 @@
 
 static NSString *const kFIRMessagingWatchKitExtensionPoint = @"com.apple.watchkit";
 
-#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH
-static NSString *const kEntitlementsAPSEnvironmentKey = @"Entitlements.aps-environment";
-#else
+#if TARGET_OS_OSX
+// macOS uses a different entitlement key than the rest of Apple's platforms:
+// https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_aps-environment
 static NSString *const kEntitlementsAPSEnvironmentKey =
     @"Entitlements.com.apple.developer.aps-environment";
-#endif
+#else
+// Entitlement key for all non-macOS platforms:
+// https://developer.apple.com/documentation/bundleresources/entitlements/aps-environment
+static NSString *const kEntitlementsAPSEnvironmentKey = @"Entitlements.aps-environment";
+#endif  // TARGET_OS_OSX
 static NSString *const kAPSEnvironmentDevelopmentValue = @"development";
 
 #pragma mark - URL Helpers


Test patch: