invertase/react-native-apple-authentication

Support for VisionOS

Closed this issue · 2 comments

I have been doing some work with this repo https://github.com/callstack/react-native-visionos

And wanted to contribute sharing what made it work for me following the instructions in this post

Here is the needed code for it to run appleAuth methods for react-native-visionos

Steps:

  1. On RNAppleAuthentication.podspec Add visionos support

s.platforms = { :ios => "9.0", :osx => "10.15", :visionos => "1.0" }

  1. Run bundle install and then bundle exec pod install. Then run build on xcode you'll find some errors

  2. To fix the errors, look for this file RNAppleAuthASAuthorizationDelegates.m
    Add these imports

#import <UIKit/UIKit.h>
#import <AuthenticationServices/AuthenticationServices.h>

Find this if

#if TARGET_OS_OSX
    return [[NSApplication sharedApplication] keyWindow];
#else
    return [[UIApplication sharedApplication] keyWindow];
#endif

And change it for this

#if TARGET_OS_OSX
    return [[NSApplication sharedApplication] keyWindow];
#else
    #if TARGET_OS_VISION
        // visionOS
        UIWindow *window = nil;
        NSSet<UIScene *> *connectedScenes = [UIApplication sharedApplication].connectedScenes;
        for (UIScene *scene in connectedScenes) {
            if (scene.activationState == UISceneActivationStateForegroundActive && [scene isKindOfClass:[UIWindowScene class]]) {
                UIWindowScene *windowScene = (UIWindowScene *)scene;
                window = windowScene.windows.firstObject;
                break;
            }
        }
        return window;
    #else
        return [[UIApplication sharedApplication] keyWindow];
    #endif
#endif

Happy to take a PR here if you want to make one? Seems very reasonable

Done in #352, thanks!