diff --git a/Application/Sources/Application/AppDelegate.swift b/Application/Sources/Application/AppDelegate.swift index fa7bca84..33758561 100644 --- a/Application/Sources/Application/AppDelegate.swift +++ b/Application/Sources/Application/AppDelegate.swift @@ -2,7 +2,8 @@ import UIKit import Firebase import FirebaseMessaging - +import RxSwift +import RxCocoa class AppDelegate: NSObject, UIApplicationDelegate { func application( @@ -58,6 +59,21 @@ extension AppDelegate: UNUserNotificationCenterDelegate { didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void ) { + let threadIdentifier = response.notification.request.content.threadIdentifier + if UIApplication.shared.applicationState == .active { + NotificationCenter.default.post( + name: Notification.Name("touchNotification"), + object: nil, + userInfo: + [ + "threadIdentifier": threadIdentifier + ] + ) + } else { + let userDefault = UserDefaults.standard + userDefault.set(threadIdentifier, forKey: "threadIdentifier") + userDefault.synchronize() + } completionHandler() } diff --git a/Application/Sources/Scene/Main/MainView.swift b/Application/Sources/Scene/Main/MainView.swift index c0764fe3..6efd9fd3 100644 --- a/Application/Sources/Scene/Main/MainView.swift +++ b/Application/Sources/Scene/Main/MainView.swift @@ -2,9 +2,16 @@ import SwiftUI import SemicolonDesign import XNavigationAndTab +import NotificationService struct MainView: View { @EnvironmentObject var xquareRouter: XquareRouter + let activeNotification = NotificationCenter.default.publisher( + for: NSNotification.Name("touchNotification") + ) + let backgroundNotification = NotificationCenter.default.publisher( + for: NSNotification.Name(UIApplication.didBecomeActiveNotification.rawValue) + ) let homeView: HomeView let scheduleView: ScheduleView let feedView: FeedView @@ -19,5 +26,57 @@ struct MainView: View { applicationView, entireView )} + .onReceive(activeNotification, perform: { + if xquareRouter.stack.count > 2 { + xquareRouter.dismissLast() + } + guard let threadIdentifier = NotificationTopic( + rawValue: (($0.userInfo!["threadIdentifier"] as? String)!) + ), let index = topicToPage(topic: threadIdentifier).0 else { return } + self.xquareRouter.moveTabTo(index: index) + if let page = topicToPage(topic: threadIdentifier).1 { + self.xquareRouter.navigateTo(page) + } + }) + .onReceive(backgroundNotification, perform: { _ in + if xquareRouter.stack.count > 2 { + xquareRouter.dismissLast() + } + let userDefault = UserDefaults.standard + guard let threadIdentifier = userDefault.string(forKey: "threadIdentifier"), + let index = topicToPage(topic: NotificationTopic(rawValue: threadIdentifier)!).0 else { + return + } + xquareRouter.moveTabTo(index: index) + if let page = topicToPage(topic: NotificationTopic(rawValue: threadIdentifier)!).1 { + xquareRouter.navigateTo(page) + } + userDefault.setValue(nil, forKey: "threadIdentifier") + }) + } +} + +private func topicToPage(topic: NotificationTopic) -> (Int?, XquareRoute?) { + switch topic { + case .allGoodPoint, .allPenaltyLevel, .allBadPoint: + return (0, .pointHistory) + case .feedNoticeLike, .feedBambooLike, .feedBambooComment, .feedNoticeComment: + return (2, nil) + case .applicationStay, .applicationPicnicPass, .applicationWeekendMeal, + .applicationWeekendPicnic, .applicationWeekendPicnicReservation: + return (3, nil) + case .applicationPicnic: + return (0, .outingPass) + case .applicationMoveClassRoom: + return (0, nil) + case .scheduleLocal, .scheduleSocial: + NotificationCenter.default.post( + name: NSNotification.Name("schedule"), + object: nil, + userInfo: ["isSchedule": false] + ) + return (1, nil) + default: + return (nil, nil) } } diff --git a/Application/Sources/Scene/Schedule/ScheduleView.swift b/Application/Sources/Scene/Schedule/ScheduleView.swift index eca47e1b..69464526 100644 --- a/Application/Sources/Scene/Schedule/ScheduleView.swift +++ b/Application/Sources/Scene/Schedule/ScheduleView.swift @@ -6,7 +6,9 @@ struct ScheduleView: View, XNavigationAndTabContent { @State var showTimeTableView: Bool = true let timeTableView: TimeTableView let academicScheduleView: AcademicScheduleView - + let scheduleNotification = NotificationCenter.default.publisher( + for: NSNotification.Name("schedule") + ) var tabInformation: TabInformation { TabInformation( tabItemText: "일정", @@ -39,5 +41,8 @@ struct ScheduleView: View, XNavigationAndTabContent { .padding(.leading, 5) } } + .onReceive(scheduleNotification, perform: { + self.showTimeTableView = $0.userInfo?["isSchedule"] as? Bool ?? false + }) } } diff --git a/Application/Widget/Sources/Application/XquareWidget.swift b/Application/Widget/Sources/Application/XquareWidget.swift index ec344f75..bbd55ba0 100644 --- a/Application/Widget/Sources/Application/XquareWidget.swift +++ b/Application/Widget/Sources/Application/XquareWidget.swift @@ -7,7 +7,7 @@ struct XquareWidget: WidgetBundle { var body: some Widget { XquareMealWidget() XquareScheduleWidget() -// XquareTimeTableWidget() + XquareTimeTableWidget() } } diff --git a/Services/AuthService/Sources/Plugin/JWTPulgin.swift b/Services/AuthService/Sources/Plugin/JWTPulgin.swift index 6af0b6c3..167cb034 100644 --- a/Services/AuthService/Sources/Plugin/JWTPulgin.swift +++ b/Services/AuthService/Sources/Plugin/JWTPulgin.swift @@ -44,6 +44,7 @@ final public class JWTPlugin: PluginType { let token = getToken(type: authorizable.jwtTokenType), authorizable.jwtTokenType != .none else { return request } + print(token) var request = request