Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ fastlane/screenshots/**/*.png
fastlane/test_output/
.DS_Store
xcuserdata/

# Firebase
GoogleService-Info.plist
29 changes: 29 additions & 0 deletions today-s-sound.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
9AAB90052EBDD7C50062B6B6 /* FirebaseAnalytics in Frameworks */ = {isa = PBXBuildFile; productRef = 9AAB90042EBDD7C50062B6B6 /* FirebaseAnalytics */; };
9AAB90072EBDD7C50062B6B6 /* FirebaseMessaging in Frameworks */ = {isa = PBXBuildFile; productRef = 9AAB90062EBDD7C50062B6B6 /* FirebaseMessaging */; };
9ADF457E2E950B6100E8B5A2 /* CombineMoya in Frameworks */ = {isa = PBXBuildFile; productRef = 9ADF457D2E950B6100E8B5A2 /* CombineMoya */; };
9ADF45802E950B6100E8B5A2 /* Moya in Frameworks */ = {isa = PBXBuildFile; productRef = 9ADF457F2E950B6100E8B5A2 /* Moya */; };
9ADF45822E950B6100E8B5A2 /* ReactiveMoya in Frameworks */ = {isa = PBXBuildFile; productRef = 9ADF45812E950B6100E8B5A2 /* ReactiveMoya */; };
Expand Down Expand Up @@ -43,9 +45,11 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9AAB90072EBDD7C50062B6B6 /* FirebaseMessaging in Frameworks */,
9ADF45802E950B6100E8B5A2 /* Moya in Frameworks */,
9ADF457E2E950B6100E8B5A2 /* CombineMoya in Frameworks */,
9ADF45842E950B6100E8B5A2 /* RxMoya in Frameworks */,
9AAB90052EBDD7C50062B6B6 /* FirebaseAnalytics in Frameworks */,
9ADF45822E950B6100E8B5A2 /* ReactiveMoya in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -93,6 +97,8 @@
9ADF457F2E950B6100E8B5A2 /* Moya */,
9ADF45812E950B6100E8B5A2 /* ReactiveMoya */,
9ADF45832E950B6100E8B5A2 /* RxMoya */,
9AAB90042EBDD7C50062B6B6 /* FirebaseAnalytics */,
9AAB90062EBDD7C50062B6B6 /* FirebaseMessaging */,
);
productName = "today-s-sound";
productReference = 259FC9672E890D7F001152B9 /* today-s-sound.app */;
Expand Down Expand Up @@ -124,6 +130,7 @@
minimizedProjectReferenceProxies = 1;
packageReferences = (
9ADF457C2E950ADB00E8B5A2 /* XCRemoteSwiftPackageReference "Moya" */,
9AAB90032EBDD7C50062B6B6 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */,
);
preferredProjectObjectVersion = 77;
productRefGroup = 259FC9682E890D7F001152B9 /* Products */;
Expand Down Expand Up @@ -280,8 +287,10 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = "today-s-sound/today-s-sound.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = BT89Y8GTMN;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "today-s-sound/Info.plist";
Expand All @@ -308,8 +317,10 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = "today-s-sound/today-s-sound.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = BT89Y8GTMN;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "today-s-sound/Info.plist";
Expand Down Expand Up @@ -355,6 +366,14 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
9AAB90032EBDD7C50062B6B6 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/firebase/firebase-ios-sdk";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 12.5.0;
};
};
9ADF457C2E950ADB00E8B5A2 /* XCRemoteSwiftPackageReference "Moya" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/Moya/Moya";
Expand All @@ -366,6 +385,16 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
9AAB90042EBDD7C50062B6B6 /* FirebaseAnalytics */ = {
isa = XCSwiftPackageProductDependency;
package = 9AAB90032EBDD7C50062B6B6 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
productName = FirebaseAnalytics;
};
9AAB90062EBDD7C50062B6B6 /* FirebaseMessaging */ = {
isa = XCSwiftPackageProductDependency;
package = 9AAB90032EBDD7C50062B6B6 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
productName = FirebaseMessaging;
};
9ADF457D2E950B6100E8B5A2 /* CombineMoya */ = {
isa = XCSwiftPackageProductDependency;
package = 9ADF457C2E950ADB00E8B5A2 /* XCRemoteSwiftPackageReference "Moya" */;
Expand Down
57 changes: 57 additions & 0 deletions today-s-sound/App/TodaySSoundApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,69 @@
// Created by 하승연 on 9/28/25.
//

import FirebaseCore
import FirebaseMessaging
import SwiftUI
import UserNotifications

class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate { // 3. Delegate 프로토콜 3개 추가

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool
{
FirebaseApp.configure()

UNUserNotificationCenter.current().delegate = self

let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: { granted, _ in
print("알림 권한 허용: \(granted)")
}
)

// 6. APNs에 기기 등록 요청
application.registerForRemoteNotifications()

// 7. FCM 메시징 대리자 설정
Messaging.messaging().delegate = self

return true
}

// 8. FCM 토큰을 수신했을 때 호출되는 함수 (이 토큰을 Firebase 콘솔에 입력!)
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
print("====================================")
print("Firebase (FCM) 등록 토큰: \(fcmToken ?? "토큰 없음")")
print("====================================")

// FCM 토큰을 키체인에 저장
if let fcmToken {
Keychain.setString(fcmToken, for: KeychainKey.fcmToken)
print("✅ FCM 토큰을 키체인에 저장했습니다")
}
}

// 9. APNs 등록에 성공하여 deviceToken을 받았을 때
// (FCM이 APNs 토큰을 자동으로 FCM 토큰으로 매핑하므로 이 함수 자체는 필수)
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
print("APNs device token: \(deviceToken)")
Messaging.messaging().apnsToken = deviceToken
}

// 10. APNs 등록에 실패했을 때
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("APNs 등록 실패: \(error.localizedDescription)")
}
}

@main
struct TodaySSoundApp: App {
@StateObject private var session = SessionStore()

@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate

var body: some Scene {
WindowGroup {
Group {
Expand Down
41 changes: 36 additions & 5 deletions today-s-sound/Core/AppState/SessionStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
//

import Combine
import FirebaseMessaging
import Foundation
import SwiftUI
import UIKit

@MainActor
final class SessionStore: ObservableObject {
Expand Down Expand Up @@ -36,13 +38,23 @@ final class SessionStore: ObservableObject {
} else {
print("❌ userId: (없음)")
}
if let fcmToken = Keychain.getString(for: KeychainKey.fcmToken) {
print("✅ fcmToken: \(fcmToken)")
} else {
print("❌ fcmToken: (없음)")
}
print("━━━━━━━━━━━━━━━━━━━━━━━━━━\n")
#else
print("⚠️ RELEASE 모드로 실행 중 - DEBUG 로그 비활성화")
#endif

if let savedId = Keychain.getString(for: KeychainKey.userId) {
userId = savedId
// deviceSecret, userId, fcmToken 모두 있어야 등록된 것으로 간주
let hasDeviceSecret = Keychain.getString(for: KeychainKey.deviceSecret) != nil
let hasUserId = Keychain.getString(for: KeychainKey.userId) != nil
let hasFcmToken = Keychain.getString(for: KeychainKey.fcmToken) != nil

if hasDeviceSecret, hasUserId, hasFcmToken {
userId = Keychain.getString(for: KeychainKey.userId)
isRegistered = true
} else {
isRegistered = false
Expand All @@ -63,9 +75,27 @@ final class SessionStore: ObservableObject {
return generated
}()

// 2) Combine을 사용한 비동기 API 호출
// 2) 디바이스 모델 정보 가져오기
let deviceModel = UIDevice.current.model

// 3) FCM 토큰 가져오기
let fcmToken = Messaging.messaging().fcmToken

// 4) FCM 토큰이 있으면 키체인에 저장
if let fcmToken {
Keychain.setString(fcmToken, for: KeychainKey.fcmToken)
}

// 5) 요청 객체 생성
let request = RegisterAnonymousRequest(
deviceSecret: secret,
model: deviceModel,
fcmToken: fcmToken
)

// 6) Combine을 사용한 비동기 API 호출
await withCheckedContinuation { continuation in
apiService.registerAnonymous(deviceSecret: secret)
apiService.registerAnonymous(request: request)
.sink(
receiveCompletion: { [weak self] completion in
guard let self else { return }
Expand Down Expand Up @@ -101,7 +131,7 @@ final class SessionStore: ObservableObject {
receiveValue: { [weak self] response in
guard let self else { return }

// 3) userId 저장
// 6) userId 저장
let userId = response.result.userId
Keychain.setString(userId, for: KeychainKey.userId)

Expand All @@ -120,6 +150,7 @@ final class SessionStore: ObservableObject {
func logout() {
Keychain.delete(for: KeychainKey.userId)
Keychain.delete(for: KeychainKey.deviceSecret)
Keychain.delete(for: KeychainKey.fcmToken)

userId = nil
isRegistered = false
Expand Down
3 changes: 2 additions & 1 deletion today-s-sound/Core/Network/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import Foundation
enum Config {
static var baseURL: String {
#if DEBUG
return "http://localhost:8080" // 개발 서버
return "https://www.today-sound.com"
// return "http://localhost:8080" // 개발 서버
#else
return "https://api.todays-sound.com" // 운영 서버
#endif
Expand Down
3 changes: 2 additions & 1 deletion today-s-sound/Core/Network/Provider/AuthInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ final class AuthInterceptor: RequestInterceptor {

let bypass: Set<String> = [
"/api/auth/login",
"/api/auth/refresh"
"/api/auth/refresh",
"/api/subscriptions/keywords"
]

if bypass.contains(path) {
Expand Down
Loading
Loading