Successfully reported this slideshow.
Your SlideShare is downloading. ×

For Developing URL Routing of SwiftUI App

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 22 Ad
Advertisement

More Related Content

Slideshows for you (20)

Similar to For Developing URL Routing of SwiftUI App (20)

Advertisement

Recently uploaded (20)

Advertisement

For Developing URL Routing of SwiftUI App

  1. 1. For Developing URL Routing of SwiftUI App freddi - LINE Fukuoka at potatotips (27th April,2020)
  2. 2. Goal of This Presentation - SwiftUI(SceneDelegate) URL Routing - URL Routing - iOS12
  3. 3. URL Routing - URL https://snews.app/alerm snews://alerm
  4. 4. URL Routing - - SceneDelegate URL ( ) - Routing -
  5. 5. Parse URL in AppDelegate (Old way) - AppDelegate application(_:, open:, options:) - URL // application(_:, open:, options:) -> Bool func application(_ app: UIApplication, open url: URL, ...) -> Bool { // Write down URL Parsing Procedure ... return true }
  6. 6. Parse URL in SceneDelegate // scene(_:, openURLContexts:) func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { // Write down URL Parsing Procedure ... } New - SceneDelegate scene(_:, openURLContexts:) - AppDelegate Deprecated ※ SceneDelegate
  7. 7. URL Routing - - SceneDelegate URL - Routing -
  8. 8. Route to Goal Screen from Current Screen - UIApplication.keyWindow Deprecated
  9. 9. Route to Goal Screen from Current Screen - SceneDelegate.window import UIKit import SwiftUI class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? … New
  10. 10. Route to Goal Screen from Current Screen - UIWindow SwiftUI View - … ViewController ?
  11. 11. Route to Goal Screen from Current Screen - UIWindow SwiftUI View - … ViewController ? SwiftUI .sheet ViewController present
  12. 12. Route to Goal Screen from Current Screen - UIWindow SwiftUI View - … ViewController ? UIWindow UIHostingController(VC) SwiftUI .sheet ViewController presentSwiftUI
  13. 13. Route to Goal Screen from Current Screen - UIWindow SwiftUI View - … ViewController ? UIWindow SwiftUI .sheet ViewController present .sheet .presentUIHostingController(VC) SwiftUI UIHostingController(VC) SwiftUI
  14. 14. Route to Goal Screen from Current Screen func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { let url = URLContexts.first?.url let distinationView = parseURLToDistination(url: url) var currentTopVC = window?.rootViewController while true { if let presentedVC = currentTopVC?.presentedViewController { currentTopVC = presentedVC } else { break } } currentTopVC?.present(UIHostingController(rootView: distinationView), … }
  15. 15. Route to Goal Screen from Current Screen func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { let url = URLContexts.first?.url let distinationView = parseURLToDistination(url: url) var currentTopVC = window?.rootViewController while true { if let presentedVC = currentTopVC?.presentedViewController { currentTopVC = presentedVC } else { break } } currentTopVC?.present(UIHostingController(rootView: distinationView), … } url url View VC UIHostingController View VC
  16. 16. URL Routing - - SceneDelegate URL - Routing -
  17. 17. Other Tips - Navigation Coordinator - sheet NavigationLink tag - Navigation View push - pushViewController - Navigation UINavigationController - NavigatorInsertionView( )
  18. 18. NavigatorInsertionView struct NavigatorInsertionView: View { static var contentView: AnyView? = nil var body: some View { NavigatorInsertionView.contentView ?? { () -> AnyView in assertionFailure("Could not get AnyView") return AnyView(EmptyView()) }() } }
  19. 19. NavigatorInsertionView struct NavigatorInsertionView: View NavigationLink("", destination: NavigatiorInsertionView(), tag: Coordinator.MovingState.on, selection: movingState) .frame(width: 0, height: 0, alignment: .bottom)
  20. 20. Conclusion of URL Routing of SwiftUI App - iOS13 - Coodinator - SceneDelegate scene(_ scene:, openURLContexts:) - Navigation VC present
  21. 21. https://hakata-swift.connpass.com/event/168308/

×