Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Macharg committed Mar 24, 2020
1 parent 7133d6f commit eeed34f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 30 deletions.
5 changes: 0 additions & 5 deletions Source/BugsnagClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@

#import "BugsnagConfiguration.h"
#import "BugsnagMetadata.h"
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#elif TARGET_OS_MAC
#import <AppKit/AppKit.h>
#endif

@class BugsnagSessionTracker;

Expand Down
67 changes: 43 additions & 24 deletions Source/BugsnagClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
#import "BSG_KSSystemInfo.h"
#import "BSG_KSMach.h"

#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#elif TARGET_OS_MAC
#import <AppKit/AppKit.h>
#endif

NSString *const NOTIFIER_VERSION = @"5.23.0";
NSString *const NOTIFIER_URL = @"https://github.com/bugsnag/bugsnag-cocoa";
NSString *const BSTabCrash = @"crash";
Expand Down Expand Up @@ -126,6 +132,13 @@ void BSSerializeDataCrashHandler(const BSG_KSCrashReportWriter *writer, int type
}
}

/**
* Maps an NSNotificationName to its standard (Bugsnag) name
*
* @param name The NSNotificationName (type aliased to NSString)
*
* @returns The Bugsnag-standard name, or the notification name minus the "Notification" portion.
*/
NSString *BSGBreadcrumbNameForNotificationName(NSString *name) {
NSString *readableName = notificationNameMap[name];

Expand Down Expand Up @@ -346,6 +359,9 @@ - (id)initWithConfiguration:(BugsnagConfiguration *)initConfiguration {
NSString *const kAppWillTerminate = @"App Will Terminate";
NSString *const BSGBreadcrumbLoadedMessage = @"Bugsnag loaded";

/**
* A map of notification names to human-readable strings
*/
- (void)initializeNotificationNameMap {
notificationNameMap = @{
#if TARGET_OS_TV
Expand All @@ -362,10 +378,8 @@ - (void)initializeNotificationNameMap {
UIWindowDidBecomeVisibleNotification : kWindowVisible,
UIWindowDidBecomeHiddenNotification : kWindowHidden,
UIApplicationWillTerminateNotification : kAppWillTerminate,
UIApplicationWillEnterForegroundNotification :
@"App Will Enter Foreground",
UIApplicationDidEnterBackgroundNotification :
@"App Did Enter Background",
UIApplicationWillEnterForegroundNotification : @"App Will Enter Foreground",
UIApplicationDidEnterBackgroundNotification : @"App Did Enter Background",
UIKeyboardDidShowNotification : @"Keyboard Became Visible",
UIKeyboardDidHideNotification : @"Keyboard Became Hidden",
UIMenuControllerDidShowMenuNotification : @"Did Show Menu",
Expand All @@ -380,7 +394,7 @@ - (void)initializeNotificationNameMap {
UITableViewSelectionDidChangeNotification : kTableViewSelectionChange,
UIDeviceBatteryStateDidChangeNotification : @"Battery State Changed",
UIDeviceBatteryLevelDidChangeNotification : @"Battery Level Changed",
UIDeviceOrientationDidChangeNotification : @"Orientation Changed",
UIDeviceOrientationDidChangeNotification : @"Orientation Change",
UIApplicationDidReceiveMemoryWarningNotification : @"Memory Warning",

#elif TARGET_OS_MAC
Expand Down Expand Up @@ -849,23 +863,7 @@ - (void)orientationChanged:(NSNotification *)notification {
return;
}

NSDictionary *lastBreadcrumb = [[self.configuration.breadcrumbs arrayValue] lastObject];
NSString *orientationNotifName = BSGBreadcrumbNameForNotificationName(notification.name);

if (lastBreadcrumb && [orientationNotifName isEqualToString:lastBreadcrumb[BSGKeyName]])
{
NSDictionary *metadata = lastBreadcrumb[BSGKeyMetadata];

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

// Record the breadcrumb
[[self state] addAttribute:BSGKeyOrientationChange
withValue:@{@"from" : _lastOrientation,
@"to" : orientation}
toTabWithName:BSGKeyDeviceState];
[self sendBreadcrumbForOrientationChangeNotification:notification withOrientation:orientation];

// Preserve the orientation
_lastOrientation = orientation;
Expand Down Expand Up @@ -990,8 +988,29 @@ - (void)dealloc {

- (void)sendBreadcrumbForNotification:(NSNotification *)note {
[self addBreadcrumbWithBlock:^(BugsnagBreadcrumb *_Nonnull breadcrumb) {
breadcrumb.type = BSGBreadcrumbTypeState;
breadcrumb.message = BSGBreadcrumbNameForNotificationName(note.name);
breadcrumb.type = BSGBreadcrumbTypeState;
breadcrumb.message = BSGBreadcrumbNameForNotificationName(note.name);
}];
}

/**
* Add a breadcrumb with a device orientation change. Should only called when we have
* a previous orientation to transition from.
*
* @param notification The orientation change notification
* @param orientation The current orientation
*/
- (void)sendBreadcrumbForOrientationChangeNotification:(NSNotification *)notification
withOrientation:(NSString*)orientation
{
[self addBreadcrumbWithBlock:^(BugsnagBreadcrumb *_Nonnull breadcrumb) {
breadcrumb.metadata = @{
@"from" : _lastOrientation,
@"to" : orientation
};

breadcrumb.type = BSGBreadcrumbTypeState;
breadcrumb.message = BSGBreadcrumbNameForNotificationName(notification.name);
}];
}

Expand Down
1 change: 0 additions & 1 deletion Source/BugsnagKeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ 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 eeed34f

Please sign in to comment.