@@ -12,11 +12,15 @@ import FirebaseDynamicLinks
1212import FirebaseCore
1313import FirebaseCoreInternal
1414
15+ // 들어온 링크가 공유된 코스인지, 개인 보관함에 있는 코스인지 나타내기 위한 타입입니다.
16+ enum CourseType {
17+ case publicCourse, privateCourse
18+ }
19+
1520class SceneDelegate : UIResponder , UIWindowSceneDelegate {
1621
1722 var window : UIWindow ?
1823
19-
2024 func scene( _ scene: UIScene , willConnectTo session: UISceneSession , options connectionOptions: UIScene . ConnectionOptions ) {
2125
2226 guard let _ = ( scene as? UIWindowScene ) else { return }
@@ -39,30 +43,33 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
3943 func scene( _ scene: UIScene , continue userActivity: NSUserActivity ) {
4044
4145 if let incomingURL = userActivity. webpageURL {
42- let linkHandled = DynamicLinks . dynamicLinks ( )
46+ DynamicLinks . dynamicLinks ( )
4347 . handleUniversalLink ( incomingURL) { dynamicLink, error in
4448
45- if let courseId = self . handleDynamicLink ( dynamicLink) {
46- guard let _ = ( scene as? UIWindowScene ) else { return }
49+ if let ( courseType, courseId) = self . handleDynamicLink ( dynamicLink) {
50+ guard let windowScene = scene as? UIWindowScene else { return }
51+ let window = UIWindow ( windowScene: windowScene)
52+ let navigationController = UINavigationController ( )
4753
48- if let windowScene = scene as? UIWindowScene {
49- let window = UIWindow ( windowScene: windowScene)
50-
54+ switch courseType {
55+ case . publicCourse:
5156 let courseDetailVC = CourseDetailVC ( )
52- courseDetailVC. getUploadedCourseDetail ( courseId: Int ( courseId) )
53-
54- let tabBarController = TabBarController ( )
55- let navigationController = UINavigationController ( rootViewController: tabBarController)
56- navigationController. navigationBar. isHidden = true
57+ courseDetailVC. getUploadedCourseDetail ( courseId: courseId)
5758 navigationController. pushViewController ( courseDetailVC, animated: false )
58-
59- // 코스 발견 view 로 이동
60- tabBarController. selectedIndex = 2
61- window. rootViewController = navigationController
62- window. makeKeyAndVisible ( )
63- self . window = window
64-
59+ case . privateCourse:
60+ let privateCourseDetailVC = RunningWaitingVC ( )
61+ privateCourseDetailVC. setData ( courseId: courseId, publicCourseId: nil )
62+ navigationController. pushViewController ( privateCourseDetailVC, animated: false )
6563 }
64+
65+ let tabBarController = TabBarController ( )
66+ navigationController. navigationBar. isHidden = true
67+ navigationController. viewControllers = [ tabBarController, navigationController. viewControllers. last] . compactMap { $0 }
68+
69+ tabBarController. selectedIndex = 2
70+ window. rootViewController = navigationController
71+ window. makeKeyAndVisible ( )
72+ self . window = window
6673 }
6774 }
6875 }
@@ -106,17 +113,26 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
106113 // to restore the scene back to its current state.
107114 }
108115
109- func handleDynamicLink( _ dynamicLink: DynamicLink ? ) -> String ? {
116+ func handleDynamicLink( _ dynamicLink: DynamicLink ? ) -> ( courseType : CourseType , courseId : Int ) ? {
110117 if let dynamicLink = dynamicLink, let url = dynamicLink. url,
111118 let components = URLComponents ( url: url, resolvingAgainstBaseURL: false ) ,
112119 let queryItems = components. queryItems {
120+ var courseId : Int ?
121+ var courseType : CourseType ?
122+
113123 for item in queryItems {
114- if item. name == " courseId " , let courseId = item. value {
115- // 동적링크 핸들링 하여 courseId 추출
116-
117- return courseId
124+ if item. name == " courseId " , let id = item. value, let idInt = Int ( id) {
125+ courseId = idInt
126+ courseType = . publicCourse
127+ } else if item. name == " privateCourseId " , let id = item. value, let idInt = Int ( id) {
128+ courseId = idInt
129+ courseType = . privateCourse
118130 }
119131 }
132+
133+ if let courseId = courseId, let courseType = courseType {
134+ return ( courseType, courseId)
135+ }
120136 }
121137 return nil
122138 }
0 commit comments