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.
This commit is contained in:
Andreas Linde 2014-11-14 15:43:28 +01:00
parent 3d8800b89a
commit a236351d6e

View File

@ -195,20 +195,23 @@ NSString *bit_appAnonID(void) {
// first check if we already have an install string in the keychain // first check if we already have an install string in the keychain
NSString *appAnonIDKey = @"appAnonID"; NSString *appAnonIDKey = @"appAnonID";
NSError *error = nil; __block NSError *error = nil;
appAnonID = [BITKeychainUtils getPasswordForUsername:appAnonIDKey andServiceName:bit_keychainHockeySDKServiceName() error:&error]; appAnonID = [BITKeychainUtils getPasswordForUsername:appAnonIDKey andServiceName:bit_keychainHockeySDKServiceName() error:&error];
if (!appAnonID) { if (appAnonID) {
appAnonID = bit_UUID(); 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 // 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) { if (appAnonID) {
// 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 [BITKeychainUtils storeUsername:appAnonIDKey
andPassword:appAnonID andPassword:appAnonID
forServiceName:bit_keychainHockeySDKServiceName() forServiceName:bit_keychainHockeySDKServiceName()
updateExisting:YES updateExisting:YES
accessibility:kSecAttrAccessibleWhenUnlockedThisDeviceOnly accessibility:kSecAttrAccessibleWhenUnlockedThisDeviceOnly
error:&error]; error:&error];
});
} }
} }
}); });