Skip to content

Commit

Permalink
Update sample to print install error
Browse files Browse the repository at this point in the history
  • Loading branch information
GLinnik21 committed Jul 13, 2024
1 parent 8cc5bcb commit 12482c6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
32 changes: 28 additions & 4 deletions Samples/Common/Sources/LibraryBridge/RecordingSample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,33 @@
import Foundation
import KSCrashRecording

public class RecordingSample {
public static func simpleInstall() {
let config = KSCrashConfiguration()
KSCrash.shared().install(with: config)
public struct RecordingSample {
public enum InstallationError: Error, LocalizedError {
case kscrashError(String)
case unexpectedError(String)

public var errorDescription: String? {
switch self {
case .kscrashError(let message), .unexpectedError(let message):
return message
}
}
}

public static func install() -> Result<Void, InstallationError> {
do {
let config = KSCrashConfiguration()
try KSCrash.shared().install(with: config)
print("KSCrash installed successfully")
return .success(())
} catch let error as KSCrashInstallError {
let message = error.localizedDescription
print("Failed to install KSCrash: \(message)")
return .failure(.kscrashError(message))
} catch {
let message = error.localizedDescription
print("Unexpected error during KSCrash installation: \(message)")
return .failure(.unexpectedError(message))
}
}
}
21 changes: 18 additions & 3 deletions Samples/Common/Sources/SampleUI/SampleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ import LibraryBridge
import CrashTriggers

public struct SampleView: View {
@State private var showingInstallAlert = false
@State private var installErrorMessage: String = ""

public init() { }

public var body: some View {
NavigationView {
List {
Expand All @@ -50,8 +53,20 @@ public struct SampleView: View {
}
.navigationTitle("KSCrash Sample")
}
.onAppear {
RecordingSample.simpleInstall()
.onAppear(perform: installKSCrash)
.alert(isPresented: $showingInstallAlert) {
Alert(
title: Text("Installation Failed"),
message: Text(installErrorMessage),
dismissButton: .default(Text("OK"))
)
}
}

private func installKSCrash() {
if case let .failure(error) = RecordingSample.install() {
installErrorMessage = error.localizedDescription
showingInstallAlert = true
}
}
}

0 comments on commit 12482c6

Please sign in to comment.