Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect appVersion override when serialising KSCrash report #292

Merged
merged 3 commits into from
Jul 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

## 5.X.X (TBD)

### Bug Fixes

* Respect appVersion override when serialising KSCrash report [#292](https://github.com/bugsnag/bugsnag-cocoa/pull/292)

## 5.16.0 (02 Jul 2018)

This release alters the behaviour of the notifier to track sessions automatically.
Expand Down
4 changes: 2 additions & 2 deletions Source/BugsnagCrashReport.m
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ - (instancetype)initWithKSReport:(NSDictionary *)report {
_context = BSGParseContext(report, _metaData);
_deviceState = BSGParseDeviceState(report);
_device = BSGParseDevice(report);
_app = BSGParseApp(report[BSGKeySystem]);
_appState = BSGParseAppState(report[BSGKeySystem]);
_app = BSGParseApp(report);
_appState = BSGParseAppState(report);
_groupingHash = BSGParseGroupingHash(report, _metaData);
_overrides = [report valueForKeyPath:@"user.overrides"];
_customException = BSGParseCustomException(report, [_errorClass copy],
Expand Down
19 changes: 14 additions & 5 deletions Source/BugsnagKSCrashSysInfoParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@
}

NSDictionary *BSGParseApp(NSDictionary *report) {
NSDictionary *system = report[BSGKeySystem];

NSMutableDictionary *appState = [NSMutableDictionary dictionary];

NSDictionary *stats = report[@"application_stats"];
NSDictionary *stats = system[@"application_stats"];

NSInteger activeTimeSinceLaunch =
[stats[@"active_time_since_launch"] doubleValue] * 1000.0;
Expand All @@ -73,23 +75,30 @@
BSGDictSetSafeObject(appState, @(activeTimeSinceLaunch),
@"durationInForeground");

BSGDictSetSafeObject(appState, report[BSGKeyExecutableName], BSGKeyName);
BSGDictSetSafeObject(appState, system[BSGKeyExecutableName], BSGKeyName);
BSGDictSetSafeObject(appState,
@(activeTimeSinceLaunch + backgroundTimeSinceLaunch),
@"duration");
BSGDictSetSafeObject(appState, stats[@"application_in_foreground"],
@"inForeground");
BSGDictSetSafeObject(appState, report[@"CFBundleIdentifier"], BSGKeyId);
BSGDictSetSafeObject(appState, system[@"CFBundleIdentifier"], BSGKeyId);
return appState;
}

NSDictionary *BSGParseAppState(NSDictionary *report) {
NSDictionary *system = report[BSGKeySystem];
NSMutableDictionary *app = [NSMutableDictionary dictionary];

BSGDictSetSafeObject(app, report[@"CFBundleVersion"], @"bundleVersion");
NSString *version = [report valueForKeyPath:@"user.config.appVersion"];

if (!version) {
version = system[@"CFBundleShortVersionString"];
}

BSGDictSetSafeObject(app, system[@"CFBundleVersion"], @"bundleVersion");
BSGDictSetSafeObject(app, [Bugsnag configuration].releaseStage,
BSGKeyReleaseStage);
BSGDictSetSafeObject(app, report[@"CFBundleShortVersionString"], BSGKeyVersion);
BSGDictSetSafeObject(app, version, BSGKeyVersion);

BSGDictSetSafeObject(app, [Bugsnag configuration].codeBundleId, @"codeBundleId");

Expand Down
21 changes: 21 additions & 0 deletions Tests/BugsnagCrashReportTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -513,4 +513,25 @@ - (void)testNoReportMetaData {
XCTAssertEqual(report.metaData.count, 0);
}

- (void)testAppVersion {
NSDictionary *dictionary = [self.report toJson];
XCTAssertEqualObjects(@"1.0", dictionary[@"app"][@"version"]);
}

- (void)testAppVersionOverride {
BugsnagCrashReport *overrideReport = [[BugsnagCrashReport alloc] initWithKSReport:@{
@"system" : @{
@"CFBundleShortVersionString": @"1.1",
},
@"user": @{
@"config": @{
@"appVersion": @"1.2.3"
}
}
}];
NSDictionary *dictionary = [overrideReport toJson];
XCTAssertEqualObjects(@"1.2.3", dictionary[@"app"][@"version"]);
}


@end
4 changes: 2 additions & 2 deletions examples/swift-ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- Bugsnag (5.15.6)
- Bugsnag (5.16.0)

DEPENDENCIES:
- Bugsnag (from `../..`)
Expand All @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: "../.."

SPEC CHECKSUMS:
Bugsnag: ff5f5e3059e6a9c9d27a899f3bf3774067553483
Bugsnag: 47bcc70b43e3c616ec35d30c2ca94497b957199f

PODFILE CHECKSUM: 2107babfbfdb18f0288407b9d9ebd48cbee8661c

Expand Down