From a236351d6ee94efa6e134db48e034eba1f02563d Mon Sep 17 00:00:00 2001 From: Andreas Linde Date: Fri, 14 Nov 2014 15:43:28 +0100 Subject: [PATCH] Store anonUUID in background thread to keychain We got a (single) report that storing the anonymous UUID to the keychain can take multiple seconds causing the launch process to be locked and causing iOS to kill the app. Storing in a background thread doesn't do any harm in our case, and if it fails, it would simply cause the next app start to produce another UUID which is fine. --- Classes/BITHockeyHelper.m | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) 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]; + }); } } });