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

Change user persistence to use NSUserDefaults #590

Merged
merged 4 commits into from
May 19, 2020
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,10 @@ Bugsnag Notifiers on other platforms.
should be performed prior to calling `Bugsnag.start()`.

* User information is now persisted between application runs by default. When set a users'
email, id and name are set on `BugsnagConfiguration` they are stored in the Keychain and
email, id and name are set on `BugsnagConfiguration` they are stored in the User Defaults and
restored if an application is restarted. The values are also copied to the configuration metadata.
[#469](https://github.com/bugsnag/bugsnag-cocoa/pull/469)
[#590](https://github.com/bugsnag/bugsnag-cocoa/pull/590)

* Added callback-free method to leave breadcrumbs: `[Bugsnag leaveBreadcrumbWithMessage:metadata:andType]`
(Swift: `Bugsnag.leaveBreadcrumb(_, metadata:, type:)`)
Expand Down
16 changes: 0 additions & 16 deletions OSX/Bugsnag.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,6 @@
E7433AD31F4F64F400C082D1 /* libc++.tbd in Frameworks */,
E7433AD21F4F64EF00C082D1 /* libz.tbd in Frameworks */,
8A2C8FF01C6BC3A200846019 /* SystemConfiguration.framework in Frameworks */,
004A41F223FEE08E0092DF97 /* Security.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -520,17 +519,6 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
004A41DD23FEDF2B0092DF97 /* SSKeychain */ = {
isa = PBXGroup;
children = (
0061D8392405B23A0041C068 /* BSG_SSKeychain.h */,
0061D8372405B23A0041C068 /* BSG_SSKeychain.m */,
0061D8382405B23A0041C068 /* LICENSE */,
);
name = SSKeychain;
path = ../Source/SSKeychain;
sourceTree = "<group>";
};
8A2C8F971C6BC1F700846019 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -590,7 +578,6 @@
8A2C8FA61C6BC1F700846019 /* Info.plist */,
8A2C902F1C6BF3AC00846019 /* module.modulemap */,
E79E6B081F4E3850002B35F9 /* BSG_KSCrash */,
004A41DD23FEDF2B0092DF97 /* SSKeychain */,
);
name = Bugsnag;
sourceTree = SOURCE_ROOT;
Expand Down Expand Up @@ -1043,7 +1030,6 @@
E79E6BC41F4E3850002B35F9 /* BSG_KSMachApple.h in Headers */,
009DF96B2432872D000A8363 /* BugsnagMetadataStore.h in Headers */,
E7819BB02459759D00A7EBDD /* BugsnagNotifier.h in Headers */,
0061D83C2405B23A0041C068 /* BSG_SSKeychain.h in Headers */,
E79E6BAD1F4E3850002B35F9 /* BSG_KSCrashSentry_User.h in Headers */,
E79E6BA01F4E3850002B35F9 /* BSG_KSCrashSentry.h in Headers */,
E79E6BA91F4E3850002B35F9 /* BSG_KSCrashSentry_Private.h in Headers */,
Expand Down Expand Up @@ -1140,7 +1126,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0061D83B2405B23A0041C068 /* LICENSE in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1227,7 +1212,6 @@
E79148521FD82B36003EFEBF /* BugsnagUser.m in Sources */,
E79E6B891F4E3850002B35F9 /* BSG_KSCrash.m in Sources */,
E79E6BAC1F4E3850002B35F9 /* BSG_KSCrashSentry_User.c in Sources */,
0061D83A2405B23A0041C068 /* BSG_SSKeychain.m in Sources */,
E79148581FD82B36003EFEBF /* BugsnagFileStore.m in Sources */,
E79E6BDA1F4E3850002B35F9 /* BSG_RFC3339DateTool.m in Sources */,
E72352C21F55924A00436528 /* BSGConnectivity.m in Sources */,
Expand Down
39 changes: 16 additions & 23 deletions Source/BugsnagConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#import "BugsnagSessionTracker.h"
#import "BugsnagLogger.h"
#import "BSGConfigurationBuilder.h"
#import "BSG_SSKeychain.h"
#import "BugsnagBreadcrumbs.h"
#import "BugsnagMetadataStore.h"
#import "BSGSerialization.h"
Expand All @@ -52,7 +51,6 @@
static const int BSGApiKeyLength = 32;

// User info persistence keys
NSString * const kBugsnagUserKeychainAccount = @"BugsnagUserKeychainAccount";
NSString * const kBugsnagUserEmailAddress = @"BugsnagUserEmailAddress";
NSString * const kBugsnagUserName = @"BugsnagUserName";
NSString * const kBugsnagUserUserId = @"BugsnagUserUserId";
Expand Down Expand Up @@ -386,9 +384,10 @@ - (void)setPersistUser:(BOOL)persistUser {
*/
- (BugsnagUser *)getPersistedUserData {
@synchronized(self) {
NSString *email = [BSG_SSKeychain passwordForService:kBugsnagUserEmailAddress account:kBugsnagUserKeychainAccount];
NSString *name = [BSG_SSKeychain passwordForService:kBugsnagUserName account:kBugsnagUserKeychainAccount];
NSString *userId = [BSG_SSKeychain passwordForService:kBugsnagUserUserId account:kBugsnagUserKeychainAccount];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *email = [userDefaults objectForKey:kBugsnagUserEmailAddress];
NSString *name = [userDefaults objectForKey:kBugsnagUserName];
NSString *userId = [userDefaults objectForKey:kBugsnagUserUserId];

if (email || name || userId) {
return [[BugsnagUser alloc] initWithUserId:userId name:name emailAddress:email];
Expand All @@ -405,37 +404,30 @@ - (BugsnagUser *)getPersistedUserData {
- (void)persistUserData {
@synchronized(self) {
if (_user) {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

// Email
if (_user.email) {
[BSG_SSKeychain setPassword:_user.email
forService:kBugsnagUserEmailAddress
account:kBugsnagUserKeychainAccount];
[userDefaults setObject:_user.email forKey:kBugsnagUserEmailAddress];
}
else {
[BSG_SSKeychain deletePasswordForService:kBugsnagUserEmailAddress
account:kBugsnagUserKeychainAccount];
[userDefaults removeObjectForKey:kBugsnagUserEmailAddress];
}

// Name
if (_user.name) {
[BSG_SSKeychain setPassword:_user.name
forService:kBugsnagUserName
account:kBugsnagUserKeychainAccount];
[userDefaults setObject:_user.name forKey:kBugsnagUserName];
}
else {
[BSG_SSKeychain deletePasswordForService:kBugsnagUserName
account:kBugsnagUserKeychainAccount];
[userDefaults removeObjectForKey:kBugsnagUserName];
}

// UserId
if (_user.id) {
[BSG_SSKeychain setPassword:_user.id
forService:kBugsnagUserUserId
account:kBugsnagUserKeychainAccount];
[userDefaults setObject:_user.id forKey:kBugsnagUserUserId];
}
else {
[BSG_SSKeychain deletePasswordForService:kBugsnagUserUserId
account:kBugsnagUserKeychainAccount];
[userDefaults removeObjectForKey:kBugsnagUserUserId];
}
}
}
Expand All @@ -446,9 +438,10 @@ - (void)persistUserData {
*/
-(void)deletePersistedUserData {
@synchronized(self) {
[BSG_SSKeychain deletePasswordForService:kBugsnagUserEmailAddress account:kBugsnagUserKeychainAccount];
[BSG_SSKeychain deletePasswordForService:kBugsnagUserName account:kBugsnagUserKeychainAccount];
[BSG_SSKeychain deletePasswordForService:kBugsnagUserUserId account:kBugsnagUserKeychainAccount];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults removeObjectForKey:kBugsnagUserEmailAddress];
[userDefaults removeObjectForKey:kBugsnagUserName];
[userDefaults removeObjectForKey:kBugsnagUserUserId];
}
}

Expand Down
Loading