1
This commit is contained in:
parent
dc00ac7c4b
commit
1badbcc371
59
Sources/tcmpush/tcmpush.swift
Normal file
59
Sources/tcmpush/tcmpush.swift
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
//
|
||||||
|
// tcmpush.swift
|
||||||
|
// tcmpush
|
||||||
|
//
|
||||||
|
// Created by TA9 on 11/26/25.
|
||||||
|
//
|
||||||
|
|
||||||
|
import UIKit
|
||||||
|
import FirebaseCore
|
||||||
|
import FirebaseMessaging
|
||||||
|
|
||||||
|
public class TCMPush: NSObject {
|
||||||
|
|
||||||
|
public static let shared: TCMPush = {
|
||||||
|
let inistance = TCMPush()
|
||||||
|
return inistance
|
||||||
|
}()
|
||||||
|
|
||||||
|
private override init() {}
|
||||||
|
|
||||||
|
public var isDebugMode: Bool = false
|
||||||
|
|
||||||
|
public func printLog<T>(_ object: T,_ function: String = #function, _ line: Int = #line){
|
||||||
|
if isDebugMode {
|
||||||
|
Swift.print("""
|
||||||
|
_____ _____ _____ _____ _____ _____ _____ _____ _____ _____
|
||||||
|
| NAME = [\(function)] || LINE = [\(line)]
|
||||||
|
|>>> PRINT = \(object)
|
||||||
|
""")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public func configure() {
|
||||||
|
if FirebaseApp.app() == nil {
|
||||||
|
FirebaseApp.configure()
|
||||||
|
printLog("[TCMPush] FirebaseApp configured")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func setAPNSToken(_ deviceId: Data){
|
||||||
|
Messaging.messaging().apnsToken = deviceId
|
||||||
|
printLog("[TCMPush] set APNS Token: \(deviceId)")
|
||||||
|
}
|
||||||
|
|
||||||
|
public func getFCMToken(completion: @escaping (String?, Error?) -> Void) {
|
||||||
|
Messaging.messaging().token { [weak self] token, error in
|
||||||
|
guard let self = self else { return }
|
||||||
|
if let error = error {
|
||||||
|
self.printLog("[TCMPush] 토큰 가져오기 실패: \(error.localizedDescription)")
|
||||||
|
completion(nil, error)
|
||||||
|
} else if let token = token {
|
||||||
|
self.printLog("[TCMPush] 토큰 획득 성공: \(token)")
|
||||||
|
completion(token, nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user