Skip to content

Commit

Permalink
task(config): add new BundleVersion configuration option (#359)
Browse files Browse the repository at this point in the history
add new BundleVersion configuration option

Co-authored-by: Steve Kirkland <steve@bugsnag.com>
  • Loading branch information
rich-bugsnag and twometresteve authored Aug 10, 2021
1 parent 18f1086 commit ac239ef
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Enhancements

* Add `BundleVersion` to set the [native Cocoa option](https://docs.bugsnag.com/platforms/ios/configuration-options/#bundleversion) [#359](https://github.com/bugsnag/bugsnag-unity/pull/359)

* Update bugsnag-cocoa to v6.10.3

* Fix another rare crash in `bsg_ksmachgetThreadQueueName`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private Configuration GetDefaultConfig()
config.SessionEndpoint = new Uri("http://bs-local.com:9339/sessions");
config.Context = "My context";
config.AppVersion = "1.2.3";
config.BundleVersion = "1.2.3";
return config;
}

Expand Down
2 changes: 1 addition & 1 deletion features/ios/ios_csharp_errors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Feature: iOS smoke tests for C# errors
And the event "app.releaseStage" equals "production"
And the event "app.type" equals "iOS"
And the event "app.version" equals "1.2.3"
# And the event "app.bundleVersion" equals "???"
And the event "app.bundleVersion" equals "1.2.3"
# And the event "app.versionCode" equals "1"
# And the error payload field "events.0.app.durationInForeground" is greater than 0
# And the event "app.inForeground" equals "true"
Expand Down
23 changes: 16 additions & 7 deletions src/BugsnagUnity.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

void bugsnag_setAutoNotify(bool autoNotify);

void bugsnag_setBundleVersion(const void *configuration, char *bundleVersion);

void bugsnag_setContext(const void *configuration, char *context);
void bugsnag_setContextConfig(const void *configuration, char *context);

Expand Down Expand Up @@ -94,6 +96,11 @@ void bugsnag_setAppHangThresholdMillis(const void *configuration, NSUInteger app
((__bridge BugsnagConfiguration *)configuration).appHangThresholdMillis = appHangThresholdMillis;
}

void bugsnag_setBundleVersion(const void *configuration, char *bundleVersion) {
NSString *ns_bundleVersion = bundleVersion == NULL ? nil : [NSString stringWithUTF8String: bundleVersion];
((__bridge BugsnagConfiguration *)configuration).bundleVersion = ns_bundleVersion;
}

void bugsnag_setContext(const void *configuration, char *context) {
NSString *ns_Context = context == NULL ? nil : [NSString stringWithUTF8String: context];
[Bugsnag.client setContext:ns_Context];
Expand All @@ -114,13 +121,13 @@ void bugsnag_setEnabledBreadcrumbTypes(const void *configuration, const char *ty
((__bridge BugsnagConfiguration *)configuration).enabledBreadcrumbTypes = BSGEnabledBreadcrumbTypeAll;
return;
}

((__bridge BugsnagConfiguration *)configuration).enabledBreadcrumbTypes = BSGEnabledBreadcrumbTypeNone;

for (int i = 0; i < count; i++) {
const char *enabledType = types[i];
if (enabledType != nil) {

NSString *typeString = [[NSString alloc] initWithUTF8String:enabledType];

if([typeString isEqualToString:@"Navigation"])
Expand Down Expand Up @@ -167,7 +174,7 @@ void bugsnag_setEnabledErrorTypes(const void *configuration, const char *types[]
for (int i = 0; i < count; i++) {
const char *enabledType = types[i];
if (enabledType != nil) {

NSString *typeString = [[NSString alloc] initWithUTF8String:enabledType];

if([typeString isEqualToString:@"AppHangs"])
Expand Down Expand Up @@ -239,7 +246,7 @@ void bugsnag_setMetadata(const void *configuration, const char *tab, const char
}

void bugsnag_retrieveMetaData(const void *metadata, void (*callback)(const void *instance, const char *tab,const char *keys[], int keys_size, const char *values[], int values_size)) {

for (NSString* sectionKey in [Bugsnag.client metadata].dictionary.allKeys) {
NSDictionary* sectionDictionary = [[Bugsnag.client metadata].dictionary valueForKey:sectionKey];
NSArray *keys = [sectionDictionary allKeys];
Expand All @@ -258,7 +265,7 @@ void bugsnag_retrieveMetaData(const void *metadata, void (*callback)(const void
free(c_keys);
free(c_values);
}

}

void bugsnag_removeMetadata(const void *configuration, const char *tab) {
Expand Down Expand Up @@ -341,7 +348,9 @@ void bugsnag_retrieveBreadcrumbs(const void *managedBreadcrumbs, void (*breadcru
void bugsnag_retrieveAppData(const void *appData, void (*callback)(const void *instance, const char *key, const char *value)) {
NSDictionary *sysInfo = [BSG_KSSystemInfo systemInfo];

callback(appData, "bundleVersion", [sysInfo[@BSG_KSSystemField_BundleVersion] UTF8String]);
NSString *bundleVersion = [Bugsnag configuration].bundleVersion ?: sysInfo[@BSG_KSSystemField_BundleVersion];
callback(appData, "bundleVersion", [bundleVersion UTF8String]);

callback(appData, "id", [sysInfo[@BSG_KSSystemField_BundleID] UTF8String]);
callback(appData, "type", [sysInfo[@BSG_KSSystemField_SystemName] UTF8String]);
NSString *version = [Bugsnag configuration].appVersion ?: sysInfo[@BSG_KSSystemField_BundleShortVersion];
Expand Down
4 changes: 3 additions & 1 deletion src/BugsnagUnity/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class Configuration : IConfiguration

public const string DefaultSessionEndpoint = "https://sessions.bugsnag.com";

public string BundleVersion { get; set; }

public Configuration(string apiKey)
{
ApiKey = apiKey;
Expand Down Expand Up @@ -122,7 +124,7 @@ public virtual LogType NotifyLogLevel
}
}

private bool _autoDetectErrors = true;
private bool _autoDetectErrors = true;

[Obsolete("AutoNotify is deprecated, please use AutoDetectErrors instead.", false)]
public virtual bool AutoNotify
Expand Down
2 changes: 2 additions & 0 deletions src/BugsnagUnity/IConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,7 @@ public interface IConfiguration
string DotnetApiCompatibility { get; set; }

ulong AppHangThresholdMillis { get; set; }

string BundleVersion { get; set; }
}
}
1 change: 1 addition & 0 deletions src/BugsnagUnity/Native/Cocoa/NativeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ IntPtr CreateNativeConfig(IConfiguration config)
NativeCode.bugsnag_setAppVersion(obj, config.AppVersion);
NativeCode.bugsnag_setNotifyUrl(obj, config.Endpoint.ToString());
NativeCode.bugsnag_setMaxBreadcrumbs(obj, config.MaximumBreadcrumbs);
NativeCode.bugsnag_setBundleVersion(obj, config.BundleVersion);
if (config.AppHangThresholdMillis > 0)
{
NativeCode.bugsnag_setAppHangThresholdMillis(obj, config.AppHangThresholdMillis);
Expand Down
3 changes: 3 additions & 0 deletions src/BugsnagUnity/Native/Cocoa/NativeCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ partial class NativeCode
[DllImport(Import)]
internal static extern void bugsnag_setAppVersion(IntPtr configuration, string appVersion);

[DllImport(Import)]
internal static extern void bugsnag_setBundleVersion(IntPtr configuration, string bundleVersion);

[DllImport(Import)]
internal static extern void bugsnag_setNotifyUrl(IntPtr configuration, string endpoint);

Expand Down

0 comments on commit ac239ef

Please sign in to comment.