We created an application in swift that uses keychain. The application works fine when running on the device or in the simulator, but cannot access the keychain, provided that Testflight does not provide a new device that has never been installed using Xcode 6.1.
The following is a keychain code snippet:
import UIKit import Security let serviceIdentifier = "com.ourdomain" let kSecClassValue = kSecClass as NSString let kSecAttrAccountValue = kSecAttrAccount as NSString let kSecValueDataValue = kSecValueData as NSString let kSecClassGenericPasswordValue = kSecClassGenericPassword as NSString let kSecAttrServiceValue = kSecAttrService as NSString let kSecMatchLimitValue = kSecMatchLimit as NSString let kSecReturnDataValue = kSecReturnData as NSString let kSecMatchLimitOneValue = kSecMatchLimitOne as NSString class KeychainManager { class func setString(value: NSString, forKey: String) { self.save(serviceIdentifier, key: forKey, data: value) } class func stringForKey(key: String) -> NSString? { var token = self.load(serviceIdentifier, key: key) return token } class func removeItemForKey(key: String) { self.save(serviceIdentifier, key: key, data: "") } class func save(service: NSString, key: String, data: NSString) { var dataFromString: NSData = data.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
After the application was already installed on the device using Xcode 6.1, I noticed that the " serviceIdentifier " - com.ourdomain "was incorrect and the application package identifier did not match, as required during the configuration.
Then I changed the value of " serviceIdentifier " to match the package identifier - " com.ourdomain.appname ", however, the application simply will not work on the device if using Testflight. I am sure that this is due to the fact that the device already has a keychain for the package identifier installed with the wrong identifier, but I canβt figure out how to get around this, either to delete the keychain when the application is deleted, or to get the profile profile of the existing keyring (with invalid id)
Any help would be greatly appreciated. thanks in advance
source share