You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
푸시 알림을 탭했을 때 Notifications 에서 newMessagePublisher 퍼블리셔를 통해 Message enum 타입으로 파싱된 객체를 퍼블리싱 합니다. Message 는 .notice, .custom 두가지 케이스를 제공하고 있으며 associatedValue 를 가지고 필요한 액션을 처리할 수 있습니다.
ContentView()
// MARK: 푸시 알림을 탭 했을 때 호출
.onReceive(newMessagePublisher){ message inswitch message {
// 새 공지
caselet.notice(notice):self.newNotice = notice
// 커스텀 알림
caselet.custom(title, body, link):guardlet link,let url =URL(string: link)else{return}UIApplication.shared.open(url)}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
푸시 알림 구성
서버에서 푸시 알림을 전송하는 코드는 아래와 같습니다. (링크)
setTitle(_:)
과setBody(_:)
를 통해 주입된 값은 푸시 알림 페이로드의"aps"
내"alert"
하위 값으로 들어갑니다putAllData(_:)
를 통해 주입된 값은 인스터스의 멤버 이름을 키값으로 하여"aps"
와 동일한 레이어에 추가 됩니다.그리고
"aps"
와 데이터는"payload"
를 키로 갖는 값에 들어갑니다. (FCM 메세지 정보 문서)앱에서의 처리
Notifications
PushNotifications
라이브러리에 정의된Notifications
는 다음과 같은 푸시 알림 관련 로직을 처리합니다.Notifications
는UIApplicationDelegate
를 준수하고 있기 때문에@UIApplicationDelegateAdaptor
프로퍼티래퍼를 사용하여 SwiftUI 에서 사용할 수 있습니다.newMessagePublisher
푸시 알림을 탭했을 때
Notifications
에서newMessagePublisher
퍼블리셔를 통해Message
enum 타입으로 파싱된 객체를 퍼블리싱 합니다.Message
는.notice
,.custom
두가지 케이스를 제공하고 있으며associatedValue
를 가지고 필요한 액션을 처리할 수 있습니다.Beta Was this translation helpful? Give feedback.
All reactions