Skip to content

Commit

Permalink
feat: allow setting bugsplat database from code (#15)
Browse files Browse the repository at this point in the history
* add setBugSplatDatabase to BugSplat interface

* move setServerUrl initialization from Info.plist into BugSplat init

* setBugSplatDatabase overrides setServerUrl by a new value
  • Loading branch information
zavitax authored Feb 20, 2025
1 parent 2f73d78 commit 39452df
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
3 changes: 3 additions & 0 deletions BugSplat.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ 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;

/** Set the user name that should used in the SDK components
Right now this is used by the Crash Manager to attach to a crash report.
Expand Down
41 changes: 26 additions & 15 deletions BugSplat.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ - (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 @@ -64,25 +80,12 @@ - (instancetype)init
- (void)start
{
NSLog(@"BugSplat start...");

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

// NSAssert is set to be ignored in this library in Release builds
NSAssert(NO, @"BugSplatDatabase is missing from your Info.plist - Please add this key/value to the your app's Info.plist");
}

NSString *bugSplatDatabase = (NSString *)bugSplatDatabaseValue;
NSLog(@"BugSplat BugSplatDatabase set as [%@]", bugSplatDatabase);

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


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

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

Expand All @@ -101,6 +104,14 @@ - (NSBundle *)bundle
return [NSBundle mainBundle]; // return app's main bundle, not BugSplat framework's bundle
}

- (void)setBugSplatDatabase:(NSString *)bugSplatDatabase
{
NSString *serverURL = [NSString stringWithFormat: @"https://%@.bugsplat.com/", bugSplatDatabase];

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

- (void)setUserID:(NSString *)userID
{
_userID = userID;
Expand Down

0 comments on commit 39452df

Please sign in to comment.