import ReactAppDependencyProviderimport React_RCTAppDelegateimport UIKitimport UserNotifications@mainclass AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate { var window: UIWindow? var reactNativeDelegate: ReactNativeDelegate? var reactNativeFactory: RCTReactNativeFactory? func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil ) -> Bool { let delegate = ReactNativeDelegate() let factory = RCTReactNativeFactory(delegate: delegate) delegate.dependencyProvider = RCTAppDependencyProvider() reactNativeDelegate = delegate reactNativeFactory = factory window = UIWindow(frame: UIScreen.main.bounds) factory.startReactNative( withModuleName: "yourAppName", in: window, launchOptions: launchOptions ) UNUserNotificationCenter.current().delegate = self return true } // MARK: - Push Notification Delegate Methods func application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data ) { // Assuming RNCPushNotificationIOS has a static method or instance method available in Swift // You might need to check the specific library documentation for the correct Swift usage. // Example (syntax may vary based on RNCPushNotificationIOS Swift bridging): RNCPushNotificationIOS.didRegisterForRemoteNotifications(withDeviceToken: deviceToken) } func application( _ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError ) { // Example: RNCPushNotificationIOS.didFailToRegisterForRemoteNotificationsWithError(error) } func application( _ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void ) { // Example: RNCPushNotificationIOS.didReceiveRemoteNotification( userInfo, fetchCompletionHandler: completionHandler) } // MARK: - UNUserNotificationCenterDelegate Methods func userNotificationCenter( _ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void ) { // Example: RNCPushNotificationIOS.didReceive(response) completionHandler() // Call the completion handler } func userNotificationCenter( _ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void ) { // Example: completionHandler([.sound, .list, .banner, .badge]) // Or the options you need } // MARK: - Deep Linking / URL Scheme Handling func application( _ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:] ) -> Bool { return RCTLinkingManager.application(application, open: url, options: options) } // For Universal Links func application( _ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void ) -> Bool { return RCTLinkingManager.application( application, continue: userActivity, restorationHandler: restorationHandler) }}class ReactNativeDelegate: RCTDefaultReactNativeFactoryDelegate { override func sourceURL(for bridge: RCTBridge) -> URL? { self.bundleURL() } override func bundleURL() -> URL? { #if DEBUG RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index") #else Bundle.main.url(forResource: "main", withExtension: "jsbundle") #endif }}
This PR adds an alternative setup option for iOS projects using Swift, introduced in React Native v0.79.0. The new section provides developers with the necessary AppDelegate.swift implementation for handling deep links.
It includes new Swift code snippets for configuring deep linking in the AppDelegate.swift file, enhancing the documentation for users implementing Universal Links in their React Native applications. The previous content has been slightly modified for clarity.