Skip to content

Commit

Permalink
Merge pull request #1022 from bugsnag/nickdowell/fix-missing-device-info
Browse files Browse the repository at this point in the history
[PLAT-6136] Fix missing / invalid device info when UIKit is not available
  • Loading branch information
nickdowell authored Mar 5, 2021
2 parents dc551c9 + b4e2979 commit 6894ac1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Bugsnag/Client/BugsnagClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,10 @@ - (void)metadataChanged:(BugsnagMetadata *)metadata {
*/
#if BSG_PLATFORM_IOS
- (void)batteryChanged:(NSNotification *)notification {
if (![UIDEVICE currentDevice]) {
return;
}

NSNumber *batteryLevel = @([UIDEVICE currentDevice].batteryLevel);
BOOL charging = [UIDEVICE currentDevice].batteryState == UIDeviceBatteryStateCharging ||
[UIDEVICE currentDevice].batteryState == UIDeviceBatteryStateFull;
Expand Down
29 changes: 19 additions & 10 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSSystemInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -371,25 +371,34 @@ + (NSDictionary *)systemInfo {
#ifdef __clang_version__
sysInfo[@BSG_KSSystemField_ClangVersion] = @__clang_version__;
#endif
#if BSG_HAS_UIDEVICE
sysInfo[@BSG_KSSystemField_SystemName] = [UIDEVICE currentDevice].systemName;
sysInfo[@BSG_KSSystemField_SystemVersion] = [UIDEVICE currentDevice].systemVersion;
#else
#if TARGET_OS_IOS
// Note: This does not match UIDevice.currentDevice.systemName for versions
// prior to (and some versions of) iOS 9 where the systemName was reported
// as "iPhone OS". UIDevice gets its data from MobileGestalt which is a
// private API. /System/Library/CoreServices/SystemVersion.plist contains
// the information we need but will contain the macOS information when
// running on the Simulator.
sysInfo[@BSG_KSSystemField_SystemName] = @"iOS";
#elif TARGET_OS_OSX
sysInfo[@BSG_KSSystemField_SystemName] = @"Mac OS";
#elif TARGET_OS_TV
sysInfo[@BSG_KSSystemField_SystemName] = @"tvOS";
#endif
NSOperatingSystemVersion version =
[NSProcessInfo processInfo].operatingSystemVersion;
NSString *systemVersion;
if (version.patchVersion == 0) {
systemVersion =
[NSString stringWithFormat:@"%ld.%ld", version.majorVersion,
version.minorVersion];
[NSString stringWithFormat:@"%ld.%ld",
(long)version.majorVersion, (long)version.minorVersion];
} else {
systemVersion = [NSString
stringWithFormat:@"%ld.%ld.%ld", version.majorVersion,
version.minorVersion, version.patchVersion];
systemVersion =
[NSString stringWithFormat:@"%ld.%ld.%ld",
(long)version.majorVersion, (long)version.minorVersion,
(long)version.patchVersion];
}
sysInfo[@BSG_KSSystemField_SystemVersion] = systemVersion;
#endif

if ([self isSimulatorBuild]) {
NSString *model = [NSProcessInfo processInfo]
.environment[BSGKeySimulatorModelId];
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

## TBD

### Bug fixes

* Fix missing `osName` and `osVersion` for errors reported from app extensions that do not link against UIKit.
[#1022](/~https://github.com/bugsnag/bugsnag-cocoa/pull/1022)

## 6.7.0 (2021-03-03)

### Enhancements
Expand Down

0 comments on commit 6894ac1

Please sign in to comment.