-
Notifications
You must be signed in to change notification settings - Fork 0
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
[IDLE-393] FCM SDK를 설치하고 해당 기능을 담당하는 객체를 만든다. #75
Changes from all commits
b121934
df5e135
90c37fe
0994a42
dae6b2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict/> | ||
<dict> | ||
<key>aps-environment</key> | ||
<string>development</string> | ||
</dict> | ||
</plist> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// | ||
// FCMService.swift | ||
// Idle-iOS | ||
// | ||
// Created by choijunios on 9/24/24. | ||
// | ||
|
||
import Foundation | ||
import BaseFeature | ||
import UseCaseInterface | ||
import PresentationCore | ||
|
||
|
||
import FirebaseMessaging | ||
|
||
class FCMService: NSObject { | ||
|
||
@Injected var notificationUseCase: NotificationUseCase | ||
|
||
override public init() { | ||
super.init() | ||
Messaging.messaging().delegate = self | ||
|
||
|
||
// Notification설정 | ||
subscribeNotification() | ||
} | ||
|
||
func subscribeNotification() { | ||
|
||
NotificationCenter.default.addObserver( | ||
forName: .requestTransportTokenToServer, | ||
object: nil, | ||
queue: nil) { [weak self] _ in | ||
|
||
guard let self else { return } | ||
|
||
if let token = Messaging.messaging().fcmToken { | ||
|
||
notificationUseCase.setNotificationToken( | ||
token: token) { result in | ||
|
||
print("FCMService 토큰 전송 \(result ? "완료" : "실패")") | ||
} | ||
} | ||
} | ||
|
||
NotificationCenter.default.addObserver( | ||
forName: .requestDeleteTokenFromServer, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 로그아웃, 회원탈퇴 이후 호출되는 코드일 것 같습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이유를 잘 모르겠습니다 멘토님🥲 힌트 주실 수 있으실까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 먼저 구현체에 어떤 내용을 작성할지 생각해봅시다 😎 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 구현체에는 서버로부터 FCM을 전송하기위한 객체와 유저정보를 가져오는 객체가 필요할 것 같습니다! 먼저 유저정보를 가져온 후 토큰을 서버로 전송하는 방법으로 개발할 것 같습니다 |
||
object: nil, | ||
queue: nil) { [weak self] _ in | ||
|
||
guard let self else { return } | ||
|
||
notificationUseCase.deleteNotificationToken(completion: { result in | ||
print("FCMService 토큰 삭제 \(result ? "완료" : "실패")") | ||
}) | ||
} | ||
} | ||
} | ||
|
||
extension FCMService: MessagingDelegate { | ||
|
||
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { | ||
|
||
if let fcmToken { | ||
|
||
print("FCM토큰: \(fcmToken)") | ||
|
||
notificationUseCase.setNotificationToken(token: fcmToken) { isSuccess in | ||
|
||
print(isSuccess ? "토큰 전송 성공" : "토큰 전송 실패") | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
extension FCMService: UNUserNotificationCenterDelegate { | ||
|
||
/// 앱이 포그라운드에 있는 경우, 노티페이케이션이 도착하기만 하면 호출된다. | ||
public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { | ||
|
||
} | ||
|
||
/// 앱이 백그라운드에 있는 경우, 유저가 노티피케이션을 통해 액션을 선택한 경우 호출 | ||
public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { | ||
|
||
print(response.notification.request.content.userInfo) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// DefaultNotificationUseCase.swift | ||
// ConcreteUseCase | ||
// | ||
// Created by choijunios on 9/26/24. | ||
// | ||
|
||
import Foundation | ||
import UseCaseInterface | ||
|
||
public class DefaultNotificationUseCase: NotificationUseCase { | ||
|
||
public init() { } | ||
|
||
public func setNotificationToken(token: String, completion: @escaping (Bool) -> ()) { | ||
|
||
//TODO: 구체적 스팩 산정 후 구현 | ||
completion(true) | ||
} | ||
|
||
public func deleteNotificationToken(completion: @escaping (Bool) -> ()) { | ||
|
||
//TODO: 구체적 스팩 산정 후 구현 | ||
completion(true) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// NotificationUseCase.swift | ||
// UseCaseInterface | ||
// | ||
// Created by choijunios on 9/26/24. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol NotificationUseCase { | ||
|
||
/// 유저와 매치되는 노티피케이션 토큰을 서버로 전송합니다. | ||
func setNotificationToken(token: String, completion: @escaping (Bool) -> ()) | ||
|
||
/// 유저와 매치되는 노티피케이션 토큰을 서버로부터 제거합니다. | ||
func deleteNotificationToken(completion: @escaping (Bool) -> ()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
푸시알림 권한 요청은 앱 실행시 바로하는것보다
앱 사용 중 알림과 관련된 페이지에서 하는게 사용자 경험에 좋습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 해당부분 팀원들과 논의해보겠습니다!