For modern React Native projects using Swift AppDelegate, follow these steps to bridge to the Objective-C code required by the library:
- Create
AppDelegate+RNAppAuth.h and add:
#import "RNAppAuthAuthorizationFlowManager.h" - Set the
Objective-C Bridging Header path in Xcode Build Settings to this file. - Update
AppDelegate.swift to conform to RNAppAuthAuthorizationFlowManager and handle the open url and continue userActivity callbacks.
@main
class AppDelegate: UIResponder, UIApplicationDelegate,
RNAppAuthAuthorizationFlowManager {
//... existing code...
// Required by RNAppAuthAuthorizationFlowManager protocol
public weak var authorizationFlowManagerDelegate:
RNAppAuthAuthorizationFlowManagerDelegate?
//... existing code...
// Handle OAuth redirect URL
func application(
_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
if let authorizationFlowManagerDelegate = self.authorizationFlowManagerDelegate
{
if authorizationFlowManagerDelegate.resumeExternalUserAgentFlow(with: url)
{
return true
}
}
return RCTLinkingManager.application(app, open: url, options: options)
}
// Handle Universal Links
func application(
_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?)
) -> Bool {
if userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let delegate = authorizationFlowManagerDelegate,
delegate.resumeExternalUserAgentFlow(with: userActivity.webpageURL)
{
return true
}
return RCTLinkingManager.application(
application,
continue: userActivity,
restorationHandler: restorationHandler
)
}
}