diff --git a/Classes/BITHockeyHelper.m b/Classes/BITHockeyHelper.m index 8da51ca00a..e60ada9372 100644 --- a/Classes/BITHockeyHelper.m +++ b/Classes/BITHockeyHelper.m @@ -195,20 +195,23 @@ NSString *bit_appAnonID(void) { // first check if we already have an install string in the keychain NSString *appAnonIDKey = @"appAnonID"; - NSError *error = nil; + __block NSError *error = nil; appAnonID = [BITKeychainUtils getPasswordForUsername:appAnonIDKey andServiceName:bit_keychainHockeySDKServiceName() error:&error]; - if (!appAnonID) { + if (appAnonID) { appAnonID = bit_UUID(); - // store this UUID in the keychain (on this device only) so we can be sure to always have the same ID upon app startups if (appAnonID) { - [BITKeychainUtils storeUsername:appAnonIDKey - andPassword:appAnonID - forServiceName:bit_keychainHockeySDKServiceName() - updateExisting:YES - accessibility:kSecAttrAccessibleWhenUnlockedThisDeviceOnly - error:&error]; + // add to keychain in a background thread, since we got reports that storing to the keychain may take several seconds sometimes and cause the app to be killed + // and we don't care about the result anyway + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ + [BITKeychainUtils storeUsername:appAnonIDKey + andPassword:appAnonID + forServiceName:bit_keychainHockeySDKServiceName() + updateExisting:YES + accessibility:kSecAttrAccessibleWhenUnlockedThisDeviceOnly + error:&error]; + }); } } });