Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions DevLog/App/Delegate/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by opfic on 5/7/25.
//

import Combine
import UIKit
import Firebase
import FirebaseAuth
Expand All @@ -15,6 +14,7 @@ import GoogleSignIn
import UserNotifications

class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate {
private let logger = Logger(category: "AppDelegate")
func application(
_ app: UIApplication,
open url: URL,
Expand All @@ -33,9 +33,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate {
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in
if let error = error {
print("Notification authorization error: \(error)")
self.logger.error("Notification authorization error", error: error)
} else {
print("Notification permission granted: \(granted)")
self.logger.info("Notification permission granted: \(granted)")
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
Expand All @@ -61,23 +61,23 @@ class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate {
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
print("APNs token: \(deviceToken.map { String(format: "%02.2hhx", $0) }.joined())")
logger.info("APNs token: \(deviceToken.map { String(format: "%02.2hhx", $0) }.joined())")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Data를 hex string으로 변환하는 로직을 Data의 extension으로 분리하여 재사용성과 가독성을 높이는 것을 제안합니다.

예를 들어, 다음과 같은 extension을 추가할 수 있습니다.

extension Data {
    var hexString: String {
        map { String(format: "%02.2hhx", $0) }.joined()
    }
}

이렇게 하면 코드가 더 간결해지고 다른 곳에서도 이 로직을 쉽게 재사용할 수 있습니다.

Suggested change
logger.info("APNs token: \(deviceToken.map { String(format: "%02.2hhx", $0) }.joined())")
logger.info("APNs token: \(deviceToken.hexString)")

Messaging.messaging().apnsToken = deviceToken
}

// APNs 등록 실패
func application(
_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error
) {
print("Failed to register APNs Token: \(error)")
logger.error("Failed to register APNs token", error: error)
}

// FCMToken 갱신
func messaging(
_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?
) {
if let fcmToken = fcmToken {
print("FCM token: \(fcmToken)")
logger.info("FCM token: \(fcmToken)")
NotificationCenter.default.post(name: .fcmToken, object: nil, userInfo: ["fcmToken": fcmToken])
}
}
Expand All @@ -90,7 +90,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate {

try await settingsRef.setData(["timeZone": TimeZone.autoupdatingCurrent.identifier], merge: true)
} catch {
print("Failed to update timeZone: \(error)")
logger.error("Failed to update timeZone", error: error)
}
}
}
Expand All @@ -103,7 +103,7 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
) {
print("Foreground notification: \(notification.request.content.userInfo)")
logger.info("Foreground notification: \(notification.request.content.userInfo)")
completionHandler([.banner, .sound, .badge])
}

Expand All @@ -113,7 +113,7 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
print("Tapped notification: \(response.notification.request.content.userInfo)")
logger.info("Tapped notification: \(response.notification.request.content.userInfo)")
// userInfo["todoId"]로 이동할 Todo 식별
let userInfo = response.notification.request.content.userInfo
NotificationCenter.default.post(name: .pushTapped, object: nil, userInfo: userInfo)
Expand Down