Perfis de chaveiro e provisionamento rápidos

Criamos um aplicativo rapidamente que usa chaveiro. O aplicativo funciona bem quando executado em um dispositivo ou no simulador, mas não pode acessar o chaveiro quando provisionado via Testflight, a menos que provisionado para um novo dispositivo que nunca teve o aplicativo instalado anteriormente via Xcode 6.1.

A seguir, um trecho do código do chaveiro:

    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)!
        // Instantiate a new default keychain query
        var keychainQuery: NSMutableDictionary = NSMutableDictionary(objects: [kSecClassGenericPasswordValue, service, key, dataFromString], forKeys: [kSecClassValue, kSecAttrServiceValue, kSecAttrAccountValue, kSecValueDataValue])

        // Delete any existing items
        SecItemDelete(keychainQuery as CFDictionaryRef)

        if data == "" { return }

        // Add the new keychain item
        var status: OSStatus = SecItemAdd(keychainQuery as CFDictionaryRef, nil)
    }

    class func load(service: NSString, key: String) -> NSString? {
        // Instantiate a new default keychain query
        // Tell the query to return a result
        // Limit our results to one item
        var keychainQuery: NSMutableDictionary = NSMutableDictionary(objects: [kSecClassGenericPasswordValue, service, key, kCFBooleanTrue, kSecMatchLimitOneValue], forKeys: [kSecClassValue, kSecAttrServiceValue, kSecAttrAccountValue, kSecReturnDataValue, kSecMatchLimitValue])

        var dataTypeRef :Unmanaged<AnyObject>?

        // Search for the keychain items
        let status: OSStatus = SecItemCopyMatching(keychainQuery, &dataTypeRef)

        let opaque = dataTypeRef?.toOpaque()

        var contentsOfKeychain: NSString?

        if let op = opaque? {
            let retrievedData = Unmanaged<NSData>.fromOpaque(op).takeUnretainedValue()

            // Convert the data retrieved from the keychain into a string
            contentsOfKeychain = NSString(data: retrievedData, encoding: NSUTF8StringEncoding)
        } else {
            return nil
        }

        return contentsOfKeychain
    }  
  }

Depois que o aplicativo já foi instalado no dispositivo via Xcode 6.1, notei que o "serviceIdentifier"-"com.ourdomain"estava incorreto e não correspondia ao identificador de pacote do aplicativo, conforme necessário no provisionamento.

Eu então mudei o "serviceIdentifier"value para corresponder ao identificador de pacote configurável -"com.ourdomain.appname"no entanto, o aplicativo simplesmente não funciona no dispositivo quando provisionado via Testflight. Estou certo de que o dispositivo já possui o chaveiro para o ID do pacote instalado com o identificador incorreto, mas não consigo entender como contornar isso. remover o chaveiro quando o aplicativo for removido ou obter o perfil de provisionamento para usar o chaveiro existente (com o identificador incorreto)

Qualquer ajuda seria muito apreciada. desde já, obrigado

questionAnswers(3)

yourAnswerToTheQuestion