Skip to content

Support UISceneDelegate #928

@jeffFG

Description

@jeffFG

Apple will soon force the use of UISceneDelegate

func application(    _ app: UIApplication, open url: URL,options: [UIApplication.OpenURLOptionsKey: Any] = [:]
  ) -> Bool {  .... 

in Appdelegate will be replaced by

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {

in UISceneDelegate

which means RNAppAuthAuthorizationFlowManagerDelegate is used by UISceneDelegate rather than AppDelegate

apple suggest call like this in UISceneDelegate


  func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    guard let urlContext = URLContexts.first else { return }
      let url = urlContext.url
      let options: [UIApplication.OpenURLOptionsKey: Any] = [
        .sourceApplication: urlContext.options.sourceApplication as Any,
        .annotation: urlContext.options.annotation as Any
      ]


    // 🔹 Resume AppAuth if in progress
    if let delegate = authorizationFlowManagerDelegate {
      _ = delegate.resumeExternalUserAgentFlow(with: url)
    
    }
    _ = RCTLinkingManager.application(UIApplication.shared, open: url, options: options)
  }
}

However , the OIDExternalUserAgentIOS is now stick to AppDelegate , so app will break

    id<UIApplicationDelegate, RNAppAuthAuthorizationFlowManager> appDelegate = (id<UIApplicationDelegate, RNAppAuthAuthorizationFlowManager>)[UIApplication sharedApplication].delegate;
    if (![[appDelegate class] conformsToProtocol:@protocol(RNAppAuthAuthorizationFlowManager)]) {
        [NSException raise:@"RNAppAuth Missing protocol conformance"
                    format:@"%@ does not conform to RNAppAuthAuthorizationFlowManager", appDelegate];
    }

i can overcome above by referencing delegate to AppDelegate by
var authorizationFlowManagerDelegate = SceneDelegate.current?.authorizationFlowManagerDelegate

But, the rootviewcontroller will move to UISceneDelegate as well , and app will still crash by NSAssert

 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
    NSAssert(presentingViewController != nil,
             @"presentingViewController cannot be nil on iOS 13");
#endif // __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
    
    _presentingViewController = presentingViewController;
  } 

It would be nice if AppAuth-IOS can support UISceneDelegate so we dont need to find workaround or patch for it

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions