Skip to content

Commit b11b8be

Browse files
authored
Expose onCrashedLastRun (#291)
2 parents 948c764 + bef803b commit b11b8be

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ _None._
3838

3939
### New Features
4040

41-
_None._
41+
- Exposed Sentry's `onCrashedLastRun` to `CrashLoggingDataProvider`.
4242

4343
### Bug Fixes
4444

Sources/Remote Logging/Crash Logging/CrashLogging.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public class CrashLogging {
8383
options.enableUserInteractionTracing = self.dataProvider.enableUserInteractionTracing
8484
options.enableUIViewControllerTracing = self.dataProvider.enableUIViewControllerTracking
8585
#endif
86+
87+
options.onCrashedLastRun = self.dataProvider.onCrashedLastRun
8688
}
8789

8890
Internals.crashLogging = self

Sources/Remote Logging/Crash Logging/CrashLoggingDataProvider.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Foundation
2+
import Sentry
23

34
#if SWIFT_PACKAGE
45
import AutomatticTracksModel
@@ -17,6 +18,9 @@ public protocol CrashLoggingDataProvider {
1718
var enableAppHangTracking: Bool { get }
1819
/// Whether HTTP client errors are captured.
1920
var enableCaptureFailedRequests: Bool { get }
21+
22+
/// A closure that will run shortly after the crash logging is initialized in case a crash was detected during the previous run.
23+
var onCrashedLastRun: ((Event) -> Void)? { get }
2024
}
2125

2226
/// Default implementations of common protocol properties
@@ -94,4 +98,8 @@ public extension CrashLoggingDataProvider {
9498
var errorEventsSamplingRate: Double {
9599
return 1.0
96100
}
101+
102+
var onCrashedLastRun: ((Event) -> Void)? {
103+
return nil
104+
}
97105
}

Tests/Tests/CrashLoggingTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ class CrashLoggingTests: XCTestCase {
196196
XCTAssertTrue(dataProvider.enableUserInteractionTracing)
197197
#endif
198198
}
199+
200+
func testOnCrashedLastRunDisabledByDefault() {
201+
let dataProvider = MockCrashLoggingDataProvider()
202+
203+
XCTAssertNil(dataProvider.onCrashedLastRun)
204+
}
199205
}
200206

201207
/// Allow throwing Strings as error

0 commit comments

Comments
 (0)