Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔀 :: (#431) FCM 분기 처리 R&D #535

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
18 changes: 17 additions & 1 deletion Application/Sources/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import UIKit

import Firebase
import FirebaseMessaging

import RxSwift
import RxCocoa
class AppDelegate: NSObject, UIApplicationDelegate {

func application(
Expand Down Expand Up @@ -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()
}

Expand Down
59 changes: 59 additions & 0 deletions Application/Sources/Scene/Main/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
7 changes: 6 additions & 1 deletion Application/Sources/Scene/Schedule/ScheduleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: "일정",
Expand Down Expand Up @@ -39,5 +41,8 @@ struct ScheduleView: View, XNavigationAndTabContent {
.padding(.leading, 5)
}
}
.onReceive(scheduleNotification, perform: {
self.showTimeTableView = $0.userInfo?["isSchedule"] as? Bool ?? false
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct XquareWidget: WidgetBundle {
var body: some Widget {
XquareMealWidget()
XquareScheduleWidget()
// XquareTimeTableWidget()
XquareTimeTableWidget()
}

}
1 change: 1 addition & 0 deletions Services/AuthService/Sources/Plugin/JWTPulgin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down