Skip to content

Commit

Permalink
(feat) Enhanced orientation breadcrumbs with explicit "from" and "to"
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Macharg committed Mar 18, 2020
1 parent 7f86293 commit 5625833
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ Bugsnag Notifiers on other platforms.
* Added `addOnSendBlock:`, `removeOnSendBlock:` and `clearOnSendBlocks` methods to `Bugsnag`
and `BugsnagConfiguration`.
(#485)[https://github.com/bugsnag/bugsnag-cocoa/pull/485]

* Enhanced device orientation change breadcrumbs. These are now reported with "from" and "to" values
in a form consistent with the Android notifier.
(#486)[https://github.com/bugsnag/bugsnag-cocoa/pull/486]

## Bug fixes

Expand Down
34 changes: 25 additions & 9 deletions Source/BugsnagClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
static NSUInteger handledCount;
static NSUInteger unhandledCount;
static bool hasRecordedSessions;
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
// The previous device orientation - iOS only
static NSString *lastOrientation = NULL;
#endif

/**
* Handler executed when the application crashes. Writes information about the
Expand Down Expand Up @@ -376,7 +380,7 @@ - (void)start {
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:nil];

[center addObserver:self
selector:@selector(lowMemoryWarning:)
name:UIApplicationDidReceiveMemoryWarningNotification
Expand Down Expand Up @@ -776,10 +780,10 @@ - (void)batteryChanged:(NSNotification *)notif {

- (void)orientationChanged:(NSNotification *)notif {
NSString *orientation;
UIDeviceOrientation deviceOrientation =
[UIDevice currentDevice].orientation;

UIDeviceOrientation currentDeviceOrientation = [UIDevice currentDevice].orientation;

switch (deviceOrientation) {
switch (currentDeviceOrientation) {
case UIDeviceOrientationPortraitUpsideDown:
orientation = @"portraitupsidedown";
break;
Expand Down Expand Up @@ -811,14 +815,26 @@ - (void)orientationChanged:(NSNotification *)notif {
[orientationNotifName isEqualToString:lastBreadcrumb[BSGKeyName]]) {
NSDictionary *metadata = lastBreadcrumb[BSGKeyMetadata];

if ([orientation isEqualToString:metadata[BSGKeyOrientation]]) {
if ([orientation isEqualToString:metadata[BSGKeyOrientation]])
return; // ignore duplicate orientation event
}
}

[[self state] addAttribute:BSGKeyOrientation
withValue:orientation
toTabWithName:BSGKeyDeviceState];
// It's not a change
if ([orientation isEqualToString:lastOrientation])
return;

// We previously had an orientation
if (lastOrientation) {
[[self state] addAttribute:BSGKeyOrientationChange
withValue:@{@"from" : lastOrientation,
@"to" : orientation}
toTabWithName:BSGKeyDeviceState];
}

// We shouldn't get here without orientation being set, but to be on the safe side:
if (orientation)
// Preserve the orientation
lastOrientation = orientation;
}

- (void)lowMemoryWarning:(NSNotification *)notif {
Expand Down
1 change: 1 addition & 0 deletions Source/BugsnagKeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static NSString *const BSGKeyLabel = @"label";
static NSString *const BSGKeySeverityReason = @"severityReason";
static NSString *const BSGKeyLogLevel = @"logLevel";
static NSString *const BSGKeyOrientation = @"orientation";
static NSString *const BSGKeyOrientationChange = @"Orientation change";
static NSString *const BSGKeySimulatorModelId = @"SIMULATOR_MODEL_IDENTIFIER";
static NSString *const BSGKeyFrameAddrFormat = @"0x%lx";
static NSString *const BSGKeySymbolAddr = @"symbolAddress";
Expand Down

0 comments on commit 5625833

Please sign in to comment.