-
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 * prj: update build version * chore: apply swift-format * feat: update graph, errorHandler feature dependencies
- Loading branch information
1 parent
cc7f65e
commit 3fffccf
Showing
5 changed files
with
59 additions
and
3 deletions.
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
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
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
55 changes: 55 additions & 0 deletions
55
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,55 @@ | ||
// | ||
// FireBaseErrorHandler.swift | ||
// SSErrorHandler | ||
// | ||
// Created by MaraMincho on 9/26/24. | ||
// Copyright © 2024 com.oksusu. All rights reserved. | ||
// | ||
|
||
import Combine | ||
import FirebaseAnalytics | ||
import Foundation | ||
import OSLog | ||
import SSNotification | ||
|
||
// MARK: - FireBaseErrorHandler | ||
|
||
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 | ||
} | ||
} |