Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase Cloud Messaging not working with visionOS #13173

Closed
mark-kinoshita opened this issue Jun 24, 2024 · 12 comments · Fixed by #13176 or #13184
Closed

Firebase Cloud Messaging not working with visionOS #13173

mark-kinoshita opened this issue Jun 24, 2024 · 12 comments · Fixed by #13176 or #13184

Comments

@mark-kinoshita
Copy link

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!
@google-oss-bot
Copy link

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

@andrewheard
Copy link
Contributor

Thank you for the detailed issue report, @mark-kinoshita! Your mention of aps-environment got me looking at

#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH
static NSString *const kEntitlementsAPSEnvironmentKey = @"Entitlements.aps-environment";
#else
static NSString *const kEntitlementsAPSEnvironmentKey =
@"Entitlements.com.apple.developer.aps-environment";
#endif
and I noticed TARGET_OS_VISION wasn't listed (TARGET_OS_IOS used to cover visionOS too). I don't have a Vision Pro to test this on myself but I think #13176 will fix the issue. Once this gets merged to main, would you be willing to try it out by temporarily setting your firebase-ios-sdk Swift Package Dependency rule to the main branch?

@mark-kinoshita
Copy link
Author

@andrewheard appreciate you looking into this so quickly! I can definitely do that👍🏽

@andrewheard
Copy link
Contributor

Thanks, @mark-kinoshita! This is merged into main now. Please re-open if you're still running into the issue.

@mark-kinoshita
Copy link
Author

@andrewheard switched to main, unfortunately I'm still seeing the same 'No aps-environment set.' error

@andrewheard andrewheard reopened this Jun 24, 2024
@andrewheard
Copy link
Contributor

Sorry to hear that @mark-kinoshita, any chance you get any useful debugging information with -FIRDebugEnabled passed as a launch argument in Xcode?

@mark-kinoshita
Copy link
Author

@andrewheard it looks like I'm getting this error:
10.29.0 - [FirebaseSessions][I-SES000000] Found unknown OSName: "visionos" while converting

Not sure if its related to FCM

@andrewheard
Copy link
Contributor

@andrewheard it looks like I'm getting this error: 10.29.0 - [FirebaseSessions][I-SES000000] Found unknown OSName: "visionos" while converting

Not sure if its related to FCM

@mark-kinoshita Unfortunately I think this is unrelated to FCM (but can be safely ignored).

@paulb777
Copy link
Member

@andrewheard If you haven't already, it looks like a full review of all the #if TARGET_OS_ ... checks are needed in Messaging. For example, handleIncomingLinkIfNeededFromMessage looks suspicious.

@andrewheard
Copy link
Contributor

@mark-kinoshita, just wanted to let you know that I added some possible fixes in #13184 (still just in main) that you might be interested in trying out.

A couple other random things to double check would be that your entitlements are added if you have a separate target for the visionOS version of your app and that the provisioning profile set in Signing & Capabilities is reasonable for visionOS.

@mark-kinoshita
Copy link
Author

@andrewheard just switched back to main and its working! I really appreciate your help on this and how quickly this was resolved 👏🏽

@andrewheard
Copy link
Contributor

Thanks for letting me know, @mark-kinoshita! Glad to hear it worked. These fixes will go out in the next Firebase release (10.29 -- around 2 weeks from now).

@firebase firebase locked and limited conversation to collaborators Jul 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.