Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
For Developing URL Routing of SwiftUI App
Search
freddi(Yuki Aki)
April 27, 2020
Technology
2k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
For Developing URL Routing of SwiftUI App
potatotips #69
https://potatotips.connpass.com/event/171532/
freddi(Yuki Aki)
April 27, 2020
More Decks by freddi(Yuki Aki)
See All by freddi(Yuki Aki)
輝け俺のViewController 〜海外iOSカンファレンス登壇編〜
freddi
4
430
Deep Dive into "any" and "some"
freddi
3
1.7k
挑戦!ISUCON de Server-side Swift 〜タイムゾーンには気をつけろ〜
freddi
0
2.2k
意外と知られてないXcode13の新しい参照カウンタ最適化オプションの挙動
freddi
2
210
How to develop SIL Optimizer in Swift Language
freddi
0
410
SwiftコンパイラがSwiftで開発できるようになる話
freddi
3
710
知ろう! ShazamKit
freddi
1
250
Swift Optimizing at Compiler World
freddi
2
910
Recap Pointfree Vol. 1~3
freddi
1
920
Other Decks in Technology
See All in Technology
1000⼈規模のClaude Enterprise運⽤を「Oktaのグループ」と「Slack」に集約する
sansantech
PRO
0
380
ハッカソンで入賞した話 @ Findy LT
asari194617
0
1.5k
長期運営で肥大化したExcelマスターデータの解消に向けた移行事例
gree_tech
PRO
0
510
Introduction to Sansan for Engineers / エンジニア向け会社紹介
sansan33
PRO
6
77k
Contract One Engineering Unit 紹介資料
sansan33
PRO
0
20k
markdown-poster Introduction
kazamori
0
110
三人寄ればチューリング完全
puhitaku
6
3.2k
[potatotips #96] Give Your AI Agent the Flutter Playbook
korodroid
0
170
IHV like なユースケースへのOpenID Connect 関連仕様の適用事例
optim
0
270
顧客の要望は2次情報である 〜アンテナを張るFDEの構造論〜
noriakioji
2
490
「面白い!」を信じ抜け。激動の時代を貫く、オンリーワン・エンジニアの条件
kizawa2020
0
230
あなたの知らないバージョン命名規則
sat
PRO
2
730
Featured
See All Featured
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.1k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
950
Un-Boring Meetings
codingconduct
0
390
Game over? The fight for quality and originality in the time of robots
wayneb77
1
250
RailsConf 2023
tenderlove
30
1.5k
GitHub's CSS Performance
jonrohan
1033
470k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
300
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
310
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Transcript
For Developing URL Routing of SwiftUI App freddi - LINE
Fukuoka at potatotips (27th April, 2020)
Goal of This Presentation - SwiftUI(SceneDelegate)Ͱ࡞ΔΞϓϦͷURL Routing - URL RoutingΛ࣮͢ΔͨΊͷϕʔεࣝΛΔ
- iOS12·Ͱͷ࣮ͷҧ͍ΛΔ
URL Routing - URLͳͲΛ։͍ͨΒಛఆͷը໘ʹભҠ͢Δ https://snews.app/alerm snews://alerm
URL Routing - ࣮͢Δͷʹඞཁͳ͜ͱ - SceneDelegateͰURLΛύʔε (طଘͷํ๏ͱҧͬͯ͘Δ) - ύʔε݁ՌΛͱʹݱࡏ։͍͍ͯΔը໘͔ΒRouting -
ݱࡏͷը໘ͷ্ʹը໘Λදࣔ͢Δํ๏
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 }
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ͷ͋ΔΞϓϦͰݺΕͳ͘ͳΔ
URL Routing - ࣮͢Δͷʹඞཁͳ͜ͱ - SceneDelegateͰURLΛύʔε - ύʔε݁ՌΛͱʹݱࡏ։͍͍ͯΔը໘͔ΒRouting - ݱࡏͷը໘ͷ্ʹը໘Λදࣔ͢Δํ๏
Route to Goal Screen from Current Screen - UIApplication.keyWindow Deprecated
Route to Goal Screen from Current Screen - SceneDelegate.window ΛΘΓʹ͏ͱྑ͍
import UIKit import SwiftUI class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? … New
Route to Goal Screen from Current Screen - UIWindow ͔ΒSwiftUIͷViewࣗମΛભҠͤ͞Δ͖ʁ
- …Ͱͳ͘ɺैདྷͲ͓ΓͷViewControllerͷํ͕ࣜྑ͍?
Route to Goal Screen from Current Screen - UIWindow ͔ΒSwiftUIͷViewࣗମΛભҠͤ͞Δ͖ʁ
- …Ͱͳ͘ɺैདྷͲ͓ΓͷViewControllerͷํ͕ࣜྑ͍? SwiftUIͷ .sheet ࣮࣭ViewControllerͷpresent
Route to Goal Screen from Current Screen - UIWindow ͔ΒSwiftUIͷViewࣗମΛભҠͤ͞Δ͖ʁ
- …Ͱͳ͘ɺैདྷͲ͓ΓͷViewControllerͷํ͕ࣜྑ͍? UIWindow UIHostingController(VC) SwiftUIͷ .sheet ࣮࣭ViewControllerͷpresent SwiftUI
Route to Goal Screen from Current Screen - UIWindow ͔ΒSwiftUIͷViewࣗମΛભҠͤ͞Δ͖ʁ
- …Ͱͳ͘ɺैདྷͲ͓ΓͷViewControllerͷํ͕ࣜྑ͍? UIWindow SwiftUIͷ .sheet ࣮࣭ViewControllerͷpresent .sheet .present UIHostingController(VC) SwiftUI UIHostingController(VC) SwiftUI
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), … }
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ͷ্ʹදࣔ
URL Routing - ࣮͢Δͷʹඞཁͳ͜ͱ - SceneDelegateͰURLΛύʔε - ύʔε݁ՌΛͱʹݱࡏ։͍͍ͯΔը໘͔ΒRouting - ݱࡏͷը໘ͷ্ʹը໘Λදࣔ͢Δํ๏
Other Tips - NavigationࢹʹೖΕΔͳΒCoordinatorύλʔϯ - sheetNavigationLinkͷtagͷϑϥάཧ͕ࡶ - NavigationͰ͖ͳViewΛpushͯ͠ભҠ͢Δͷʁ - pushViewController૬ͷͷΛऔΓѻ͑ͳ͍
- NavigationΛUINavigationControllerͱͯ͠ѻ͑ͣ - NavigatorInsertionView(߲࣍)Λར༻͢Δ
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()) }() } }
NavigatorInsertionView struct NavigatorInsertionView: View NavigationLink("", destination: NavigatiorInsertionView(), tag: Coordinator.MovingState.on, selection:
movingState) .frame(width: 0, height: 0, alignment: .bottom)
Conclusion of URL Routing of SwiftUI App - ͍͔ͭ͘ͷؔiOS13͚ʹҠߦ͢Δ͜ͱʹͳΔ -
CoodinatorͷΑ͏ͳΫϥεΛ࡞Δํ͕ΕΔ͜ͱଟ͍ - SceneDelegateͷ scene(_ scene:, openURLContexts:) - Navigation͕ͳ͍ͳΒطଘͷVCͷpresentͰ͓̺
એ
https://hakata-swift.connpass.com/event/168308/