Skip to content

Commit

Permalink
fix: ensure bugSplatDatabase defers to Info.plist value, otherwise is…
Browse files Browse the repository at this point in the history
… set only once and before start is called (#26)

* fix: ensure bugSplatDatabase is set only once and before start is called

* chore: update BugSplat.h

---------

Co-authored-by: Bobby Galli <bobbyg603@pm.me>
  • Loading branch information
ferrerod and bobbyg603 authored Feb 25, 2025
1 parent 552c60b commit e9e55c9
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ xcuserdata
xcframeworks
Vendor
archives
Tools/symbol-upload-macos
21 changes: 19 additions & 2 deletions BugSplat.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,25 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, copy, nullable) NSString *userID;

/** Set the bugsplat database name, which will override the "BugSplatDatabase" Info.plist key value */
@property (nonatomic, assign) NSString *bugSplatDatabase;
/**
* The database name BugSplat will use to construct the BugSplatDatabase URL where crash reports will be submitted.
*
* NOTES:
* By default, the BugSplat database name is pulled from the App's Info.plist.
*
* When a third party library or plugin developer is leveraging BugSplat, but the App developer incorporating
* the plugin is not using BugSplat, programmatically setting this property would be appropriate.
*
* Only one BugSplat database can be specified within an App including any third party libraries and plugins.
* This means if the Info.plist contains a BugSplat database, attempting to change this property will have no effect.
*
* Additionally, if the Info.plist does not contain a BugSplat database key and value, the first call to
* set this property will set the BugSplat database name. Any subsequent calls to set this property will have no effect.
*
* Finally, with the above considerations, if programmatic change of this property is desired, it must be set before calling
* BugSplat `start` method or it will have no effect.
*/
@property (nonatomic, copy, nullable) NSString *bugSplatDatabase;

/** Set the user name that should used in the SDK components
Expand Down
74 changes: 53 additions & 21 deletions BugSplat.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

@interface BugSplat() <BITHockeyManagerDelegate>

/** set to YES if start is called and returns successfully */
@property (atomic, assign) BOOL isStartInvoked;

/**
* Attributes represent app supplied keys and values additional to the crash report.
* Attributes will be bundled up in a BugSplatAttachment as NSData, with a filename of CrashContext.xml, MIME type of "application/xml" and encoding of "UTF-8".
Expand All @@ -28,6 +31,10 @@ @interface BugSplat() <BITHockeyManagerDelegate>

@implementation BugSplat

// internal instance variable
NSString * _bugSplatDatabase = nil;


+ (instancetype)shared
{
static BugSplat *sharedInstance = nil;
Expand All @@ -45,6 +52,8 @@ - (instancetype)init
if (self = [super init]) {
[[BITHockeyManager sharedHockeyManager] configureWithIdentifier:kHockeyIdentifierPlaceholder];

self.isStartInvoked = NO;

#if TARGET_OS_OSX
_autoSubmitCrashReport = NO;
_askUserDetails = YES;
Expand All @@ -56,22 +65,6 @@ - (instancetype)init
self.bannerImage = bannerImage;
}
#endif

id bugSplatDatabaseValue = [self.bundle objectForInfoDictionaryKey:kBugSplatDatabase];
if (bugSplatDatabaseValue == nil) {
NSLog(@"*** BugSplat init: BugSplatDatabase is missing from your Info.plist - Please add this key/value to the your app's Info.plist or use setBugSplatDatabase to set it from code ***");

// NSAssert is set to be ignored in this library in Release builds
NSAssert(NO, @"BugSplat init: BugSplatDatabase is missing from your Info.plist - Please add this key/value to the your app's Info.plist or use setBugSplatDatabase to set it from code");
} else {
NSString *bugSplatDatabase = (NSString *)bugSplatDatabaseValue;
NSLog(@"BugSplat init: BugSplat BugSplatDatabase set as [%@]", bugSplatDatabase);

NSString *serverURL = [NSString stringWithFormat: @"https://%@.bugsplat.com/", bugSplatDatabase];

NSLog(@"BugSplat init: setServerURL: [%@]", serverURL);
[[BITHockeyManager sharedHockeyManager] setServerURL:serverURL];
}
}

return self;
Expand All @@ -80,13 +73,33 @@ - (instancetype)init
- (void)start
{
NSLog(@"BugSplat start...");


if (!self.bugSplatDatabase)
{
NSLog(@"*** BugSplatDatabase is nil. Please add this key/value to the your app's Info.plist or set bugSplatDatabase before invoking start. ***");

// NSAssert is set to be ignored in this library in Release builds
NSAssert(NO, @"*** BugSplatDatabase is nil. Please add this key/value to the your app's Info.plist or set bugSplatDatabase before invoking start. ***");
self.isStartInvoked = NO; // unsuccessful return
return;
}

if (self.isStartInvoked)
{
NSLog(@"*** BugSplat `start` was already invoked. ***");
return;
}

NSLog(@"BugSplat BugSplatDatabase set as [%@]", self.bugSplatDatabase);
NSString *serverURL = [NSString stringWithFormat: @"https://%@.bugsplat.com/", self.bugSplatDatabase];

// Uncomment line below to enable HockeySDK logging
// [[BITHockeyManager sharedHockeyManager] setLogLevel:BITLogLevelVerbose];

// setServerUrl will be called from either `init` or `setBugSplatDatabase`
NSLog(@"BugSplat setServerURL: [%@]", serverURL);
[[BITHockeyManager sharedHockeyManager] setServerURL:serverURL];
[[BITHockeyManager sharedHockeyManager] startManager];
self.isStartInvoked = YES;
}

- (void)setDelegate:(id<BugSplatDelegate>)delegate
Expand All @@ -104,12 +117,31 @@ - (NSBundle *)bundle
return [NSBundle mainBundle]; // return app's main bundle, not BugSplat framework's bundle
}

- (NSString *)bugSplatDatabase
{
// defer to Info.plist value if present
NSString *bugSplatDatabaseValue = (NSString *)[self.bundle objectForInfoDictionaryKey:kBugSplatDatabase];
if (bugSplatDatabaseValue)
{
return [bugSplatDatabaseValue copy];
}

return _bugSplatDatabase;
}

- (void)setBugSplatDatabase:(NSString *)bugSplatDatabase
{
NSString *serverURL = [NSString stringWithFormat: @"https://%@.bugsplat.com/", bugSplatDatabase];
// if a value is already present, do not change it
if (self.bugSplatDatabase)
{
return;
}

NSLog(@"BugSplat setBugSplatDatabase: setServerURL: [%@]", serverURL);
[[BITHockeyManager sharedHockeyManager] setServerURL:serverURL];
// Set a value if value is not nil, and if isStartInvoked is NO
if (bugSplatDatabase && !self.isStartInvoked)
{
_bugSplatDatabase = [bugSplatDatabase copy];
}
}

- (void)setUserID:(NSString *)userID
Expand Down
3 changes: 0 additions & 3 deletions Tools/symbol-upload-macos

This file was deleted.

0 comments on commit e9e55c9

Please sign in to comment.