-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] FireBaseanalytics Error Handler 작성 #594
- Loading branch information
1 parent
387a1db
commit 0fac69e
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
Projects/Feature/SSErrorHandler/Sources/FireBaseErrorHandler.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// FireBaseErrorHandler.swift | ||
// SSErrorHandler | ||
// | ||
// Created by MaraMincho on 9/26/24. | ||
// Copyright © 2024 com.oksusu. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
import Foundation | ||
import OSLog | ||
import SSNotification | ||
import FirebaseAnalytics | ||
|
||
// MARK: - DiscordErrorHandler | ||
|
||
public final class FireBaseErrorHandler { | ||
public static let shared = FireBaseErrorHandler() | ||
var subscription: AnyCancellable? | ||
private init() {} | ||
|
||
public func registerFirebaseLogSystem() { | ||
subscription = NotificationCenter.default.publisher(for: SSNotificationName.logError) | ||
.sink { @Sendable errorObjectOutput in | ||
let errorObject = errorObjectOutput.object as? String | ||
Self.sendErrorToFirebase(errorMessage: errorObject) | ||
} | ||
} | ||
|
||
public func removeDiscordLogSystem() { | ||
subscription = nil | ||
} | ||
|
||
@Sendable private static func sendErrorToFirebase(errorMessage message: String?) { | ||
guard let message else { | ||
return | ||
} | ||
Analytics.logEvent("iOS Error", parameters: ["description": message]) | ||
} | ||
} | ||
|
||
private extension String { | ||
func splitByLength(_ length: Int) -> [String] { | ||
var result: [String] = [] | ||
var currentIndex = startIndex | ||
|
||
while currentIndex < endIndex { | ||
let nextIndex = index(currentIndex, offsetBy: length, limitedBy: endIndex) ?? endIndex | ||
result.append(String(self[currentIndex ..< nextIndex])) | ||
currentIndex = nextIndex | ||
} | ||
|
||
return result | ||
} | ||
} |