Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add Swift AppDelegate setup instructions for deep linking#1428

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
kleviss wants to merge1 commit intoreact-navigation:main
base:main
Choose a base branch
Loading
fromkleviss:feat/deep-linking-docs-add-swift-appdelegate

Conversation

kleviss
Copy link

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.

chetan-satpute reacted with thumbs up emoji
@netlifyNetlify
Copy link

netlifybot commentedMay 14, 2025

Deploy Preview forreact-navigation-docs ready!

NameLink
🔨 Latest commit0148e86
🔍 Latest deploy loghttps://app.netlify.com/sites/react-navigation-docs/deploys/682482cb267b4200081b09fa
😎 Deploy Previewhttps://deploy-preview-1428--react-navigation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to yourNetlify site configuration.

@kleviss
Copy link
Author

I think this is also related to#1425, but the changes I have made here have not created any build issues and are working perfectly fine. In my case I had set up the app with v6 before, and deep linking and everything was working, so all the configurations onXCode were done. The RN New Arch introducesAppDelegate.swift, so this was needed to be added there so it properly works.

@kleviss
Copy link
Author

This is the completeAppDelegate.swift file for my case. Note that it also includes push notifications configurations, and my actual app bundle name is replaced withyourAppName.

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  }}

@chetan-satpute
Copy link

We might want to rewrite this section using tabs

<TabsgroupId="app-delegate"><TabItemvalue="objc"label="AppDelegate.m">// ...</TabItem><TabItemvalue="swift"label="AppDelegate.swift">// ...</TabItem></Tabs>If your app is using[Universal Links](https://developer.apple.com/ios/universal-links/), you'll need to add the following code as well:<TabsgroupId="app-delegate"><TabItemvalue="objc"label="AppDelegate.m">// ...</TabItem><TabItemvalue="swift"label="AppDelegate.swift">// ...</TabItem></Tabs>

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@kleviss@chetan-satpute

[8]ページ先頭

©2009-2025 Movatter.jp