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

Feature/138 fcm #170

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,5 @@ Derived/

### Tuist managed dependencies ###
Tuist/Dependencies

GoogleService-info.plist
8 changes: 8 additions & 0 deletions Projects/App/DodamDodam.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +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>
<key>aps-environment</key>
<string>development</string>
</dict>
</plist>
6 changes: 4 additions & 2 deletions Projects/App/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let project = Project(
options: .options(
defaultKnownRegions: ["en", "ko"],
developmentRegion: "ko"
),
),
settings: .settings(
base: .init()
.otherLinkerFlags(["$(inherited) -ObjC"]),
Expand All @@ -30,11 +30,13 @@ let project = Project(
"CFBundleVersion": "1",
"UISupportedInterfaceOrientations": ["UIInterfaceOrientationPortrait"],
"UIMainStoryboardFile": "",
"UILaunchStoryboardName": "LaunchScreen"
"UILaunchStoryboardName": "LaunchScreen",
"FirebaseAppDelegateProxyEnabled": .boolean(false)
]
),
sources: ["iOS/Source/**"],
resources: ["iOS/Resource/**"],
// entitlements: .file(path: "iOS/Resource/DodamDodam.entitlements"),
scripts: [.swiftLint],
dependencies: [
.project(target: "Feature", path: .relativeToRoot("Projects/Feature")),
Expand Down
103 changes: 103 additions & 0 deletions Projects/App/iOS/Source/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//
// AppDelegate.swift
// DodamDodam
//
// Created by dgsw8th61 on 9/19/24.
//

import SwiftUI
import Firebase
import FirebaseMessaging
import DIContainer
import Domain

class AppDelegate: NSObject, UIApplicationDelegate {

let gcmMessageIDKey = "gcm.message_id"

// 앱이 켜졌을 때
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {

// 파이어베이스 설정
FirebaseApp.configure()

// Setting Up Notifications...
// 원격 알림 등록
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { _, _ in }
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}

application.registerForRemoteNotifications()

// Setting Up Cloud Messaging...
// 메세징 델리겟
Messaging.messaging().delegate = self
UNUserNotificationCenter.current().delegate = self
UIApplication.shared.registerForRemoteNotifications()
return true
}

// fcm 토큰이 등록 되었을 때
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
print("✅ AppDelegate.application.didRegisterForRemoteNotificationsWithDeviceToken - apnsToken \(deviceToken)")
Messaging.messaging().apnsToken = deviceToken
}
}

// Cloud Messaging...
extension AppDelegate: MessagingDelegate {

// fcm 등록 토큰이 갱신되었을 때
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
guard let fcmToken else {
print("❌ AppDelegate.messaging.didReceiveRegistrationToken - FCM token is nil")
return
}
print("✅ AppDelegate.Fmessaging.didReceiveRegistrationToken - fcmToken \(fcmToken)")
}
}

// User Notifications...[AKA InApp Notification...]

@available(iOS 10, *)
extension AppDelegate: UNUserNotificationCenterDelegate {

// 푸시 메세지가 앱이 켜져 있을 때 나올 때
func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification
) async -> UNNotificationPresentationOptions {
let userInfo = notification.request.content.userInfo

// Do Something With MSG Data...
if let messageID = userInfo[gcmMessageIDKey] {
print("✅ AppDelegate.userNotificationCenter.didReceive - Message ID: \(messageID)")
}
print("✅ AppDelegate.userNotificationCenter.didReceive - \(userInfo)")

return if #available(iOS 14.0, *) {
[[.list, .banner, .sound]]
} else {
[[.alert, .sound]]
}
}

// 푸시메세지를 받았을 떄
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse
) async {
let userInfo = response.notification.request.content.userInfo

// Do Something With MSG Data...
if let messageID = userInfo[gcmMessageIDKey] {
print("✅ AppDelegate.userNotificationCenter.didReceive - Message ID: \(messageID)")
}
print("✅ AppDelegate.userNotificationCenter.didReceive - \(response)")
}
}
2 changes: 2 additions & 0 deletions Projects/App/iOS/Source/AppMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import Realm
@main
struct AppMain: App {

@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

init() {
Pretendard.register()
DependencyProvider.shared.register()
Expand Down
5 changes: 3 additions & 2 deletions Projects/Data/Network/Source/Remote/RemoteInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Alamofire
import SignKit
import Domain
import DIContainer
import FirebaseMessaging

class RemoteInterceptor: RequestInterceptor {

Expand Down Expand Up @@ -73,11 +74,11 @@ class RemoteInterceptor: RequestInterceptor {
if let id = Sign.id,
let pw = Sign.password {
do {
let pushToken = try await Messaging.messaging().token()
_ = try await authRepository.postLogin(
.init(id: id, pw: pw)
.init(id: id, pw: pw, pushToken: pushToken)
)
DispatchQueue.main.async {
// self.retryCount += 1
completion(.retry)
}
} catch let error {
Expand Down
1 change: 1 addition & 0 deletions Projects/Data/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ let project = Project(
.project(target: "Domain", path: .relativeToRoot("Projects/Domain")),
.external(name: "Moya"),
.external(name: "SignKit"),
.external(name: "FirebaseMessaging"),
.project(target: "Shared", path: .relativeToRoot("Projects/Shared"))
]
),
Expand Down
4 changes: 3 additions & 1 deletion Projects/Domain/Source/Request/Auth/PostLoginRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ public struct PostLoginRequest: RequestProtocol {

public let id: String
public let pw: String
public let pushToken: String

public init(id: String, pw: String) {
public init(id: String, pw: String, pushToken: String) {
self.id = id
self.pw = pw
self.pushToken = pushToken
}
}
3 changes: 2 additions & 1 deletion Projects/Feature/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ let project = Project(
.project(target: "DIContainer", path: .relativeToRoot("Projects/DIContainer")),
.external(name: "CachedAsyncImage"),
.external(name: "SwiftUIIntrospect"),
.project(target: "Shared", path: .relativeToRoot("Projects/Shared"))
.project(target: "Shared", path: .relativeToRoot("Projects/Shared")),
.external(name: "FirebaseMessaging")
]
)
]
Expand Down
1 change: 0 additions & 1 deletion Projects/Feature/Source/All/AllView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ struct AllView: View {
.padding(.bottom, 8)
} else {
Button {
dump(flow)
flow.push(LoginView())
} label: {
HStack(spacing: 16) {
Expand Down
4 changes: 3 additions & 1 deletion Projects/Feature/Source/Auth/Login/LoginViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Combine
import SignKit
import DIContainer
import Domain
import FirebaseMessaging

class LoginViewModel: ObservableObject {

Expand All @@ -28,8 +29,9 @@ class LoginViewModel: ObservableObject {
func postLogin(_ completion: @escaping () -> Void) async {
isShowingAlert = false
do {
let pushToken = try await Messaging.messaging().token()
_ = try await authRepository.postLogin(
.init(id: idText, pw: pwText)
.init(id: idText, pw: pwText, pushToken: pushToken)
)
completion()
} catch let error {
Expand Down
117 changes: 117 additions & 0 deletions Tuist/Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"pins" : [
{
"identity" : "abseil-cpp-binary",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/abseil-cpp-binary.git",
"state" : {
"revision" : "194a6706acbd25e4ef639bcaddea16e8758a3e27",
"version" : "1.2024011602.0"
}
},
{
"identity" : "alamofire",
"kind" : "remoteSourceControl",
Expand All @@ -9,6 +18,15 @@
"version" : "5.9.1"
}
},
{
"identity" : "app-check",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/app-check.git",
"state" : {
"revision" : "3b62f154d00019ae29a71e9738800bb6f18b236d",
"version" : "10.19.2"
}
},
{
"identity" : "dds-ios",
"kind" : "remoteSourceControl",
Expand All @@ -18,6 +36,15 @@
"version" : "0.2.20"
}
},
{
"identity" : "firebase-ios-sdk",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/firebase-ios-sdk.git",
"state" : {
"revision" : "eca84fd638116dd6adb633b5a3f31cc7befcbb7d",
"version" : "10.29.0"
}
},
{
"identity" : "flowkit",
"kind" : "remoteSourceControl",
Expand All @@ -27,6 +54,69 @@
"revision" : "71ee3f7414747e16f320a6f6b424152e22d9d694"
}
},
{
"identity" : "googleappmeasurement",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleAppMeasurement.git",
"state" : {
"revision" : "fe727587518729046fc1465625b9afd80b5ab361",
"version" : "10.28.0"
}
},
{
"identity" : "googledatatransport",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleDataTransport.git",
"state" : {
"revision" : "a637d318ae7ae246b02d7305121275bc75ed5565",
"version" : "9.4.0"
}
},
{
"identity" : "googleutilities",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleUtilities.git",
"state" : {
"revision" : "57a1d307f42df690fdef2637f3e5b776da02aad6",
"version" : "7.13.3"
}
},
{
"identity" : "grpc-binary",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/grpc-binary.git",
"state" : {
"revision" : "e9fad491d0673bdda7063a0341fb6b47a30c5359",
"version" : "1.62.2"
}
},
{
"identity" : "gtm-session-fetcher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/gtm-session-fetcher.git",
"state" : {
"revision" : "a2ab612cb980066ee56d90d60d8462992c07f24b",
"version" : "3.5.0"
}
},
{
"identity" : "interop-ios-for-google-sdks",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/interop-ios-for-google-sdks.git",
"state" : {
"revision" : "2d12673670417654f08f5f90fdd62926dc3a2648",
"version" : "100.0.0"
}
},
{
"identity" : "leveldb",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/leveldb.git",
"state" : {
"revision" : "a0bc79961d7be727d258d33d5a6b2f1023270ba1",
"version" : "1.22.5"
}
},
{
"identity" : "moya",
"kind" : "remoteSourceControl",
Expand All @@ -36,6 +126,24 @@
"version" : "15.0.3"
}
},
{
"identity" : "nanopb",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/nanopb.git",
"state" : {
"revision" : "b7e1104502eca3a213b46303391ca4d3bc8ddec1",
"version" : "2.30910.0"
}
},
{
"identity" : "promises",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/promises.git",
"state" : {
"revision" : "540318ecedd63d883069ae7f1ed811a2df00b6ac",
"version" : "2.4.0"
}
},
{
"identity" : "reactiveswift",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -81,6 +189,15 @@
"version" : "0.0.2"
}
},
{
"identity" : "swift-protobuf",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-protobuf.git",
"state" : {
"revision" : "edb6ed4919f7756157fe02f2552b7e3850a538e5",
"version" : "1.28.1"
}
},
{
"identity" : "swiftui-cached-async-image",
"kind" : "remoteSourceControl",
Expand Down
1 change: 1 addition & 0 deletions Tuist/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ let package = Package(
.package(url: "https://github.com/Mercen-Lee/FlowKit", branch: "main"),
.package(url: "https://github.com/Mercen-Lee/SignKit", exact: "0.0.2"),
.package(url: "https://github.com/lorenzofiamingo/swiftui-cached-async-image", exact: "2.1.1"),
.package(url: "https://github.com/firebase/firebase-ios-sdk.git", from: "10.0.0"),
.package(url: "https://github.com/realm/realm-swift", exact: "20.0.0"),
.package(url: "https://github.com/siteline/SwiftUI-Introspect", exact: "1.3.0")
]
Expand Down