Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Structured Logs: Flush logs on SDK flush/close (#5834)
- Add masking options for screenshots (#5401)
- Add significant time change breadcrumb (#6112)

### Fixes

Expand Down
25 changes: 25 additions & 0 deletions Sources/Sentry/SentrySystemEventBreadcrumbs.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ - (void)stop
[self.notificationCenterWrapper removeObserver:self
name:UIDeviceOrientationDidChangeNotification
object:nil];
[self.notificationCenterWrapper removeObserver:self
name:UIApplicationSignificantTimeChangeNotification
object:nil];
}

- (void)dealloc
Expand All @@ -82,6 +85,7 @@ - (void)startWithDelegate:(id<SentryBreadcrumbDelegate>)delegate
[self initKeyboardVisibilityObserver];
[self initScreenshotObserver];
[self initTimezoneObserver];
[self initSignificantTimeChangeObserver];
}

- (void)initBatteryObserver:(UIDevice *)currentDevice
Expand Down Expand Up @@ -278,6 +282,27 @@ - (void)updateStoredTimezone
storeTimezoneOffset:SentryDependencyContainer.sharedInstance.dateProvider.timezoneOffset];
}

- (void)initSignificantTimeChangeObserver
{

[self.notificationCenterWrapper addObserver:self
selector:@selector(significantTimeChangeTriggered:)
name:UIApplicationSignificantTimeChangeNotification
object:nil];
}

- (void)significantTimeChangeTriggered:(NSNotification *)notification
Comment thread
philipphofmann marked this conversation as resolved.
{
SentryBreadcrumb *crumb = [[SentryBreadcrumb alloc] initWithLevel:kSentryLevelInfo
category:@"device.event"];
crumb.type = @"system";

// We don't add the timezone here, because we already add it in timezoneEventTriggered.
crumb.data = @{ @"action" : @"SIGNIFICANT_TIME_CHANGE" };

[_delegate addBreadcrumb:crumb];
}

@end

#endif // TARGET_OS_IOS && SENTRY_HAS_UIKIT
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,38 @@ class SentrySystemEventBreadcrumbsTest: XCTestCase {
}
}

func testSignificantTimeChangeNotificationBreadcrumb() throws {
sut = fixture.getSut(currentDevice: nil)

fixture.notificationCenterWrapper.post(Notification(name: UIApplication.significantTimeChangeNotification, object: nil))

XCTAssertEqual(1, fixture.delegate.addCrumbInvocations.count)

if let crumb = fixture.delegate.addCrumbInvocations.first {

XCTAssertEqual("device.event", crumb.category)
XCTAssertEqual("system", crumb.type)
XCTAssertEqual(SentryLevel.info, crumb.level)

let data = try XCTUnwrap(crumb.data, "no breadcrumb.data")
XCTAssertEqual("SIGNIFICANT_TIME_CHANGE", data["action"] as? String)
}
Comment thread
philipphofmann marked this conversation as resolved.
Outdated
}

func testSignificantTimeChangeNotificationBreadcrumb_UnsubscribeOnStop() {
sut = fixture.getSut(currentDevice: nil)

sut.stop()

let didCallRemoveObserver = fixture.notificationCenterWrapper.removeObserverWithNameAndObjectInvocations.invocations.filter { $0.name == UIApplication.significantTimeChangeNotification }.count == 1

XCTAssertTrue(didCallRemoveObserver, "Stop didn't call remove observer for UIApplicationSignificantTimeChangeNotification")
}

func testStopCallsSpecificRemoveObserverMethods() {
sut = fixture.getSut(currentDevice: nil)
sut.stop()
XCTAssertEqual(fixture.notificationCenterWrapper.removeObserverWithNameAndObjectInvocations.count, 6)
XCTAssertEqual(fixture.notificationCenterWrapper.removeObserverWithNameAndObjectInvocations.count, 7)
}

private func postBatteryLevelNotification(uiDevice: UIDevice?) {
Expand Down
Loading