xcode – Keychain adhoc发行版
发布时间:2020-12-14 19:24:12 所属栏目:百科 来源:网络整理
导读:首先,我们正在开发一个目前使用 Swift / Xcode 6.1 GM 2进行开发的iOS应用程序. 在临时分发应用程序时,我们遇到了一些令人困惑的钥匙串访问问题,并且在跟踪原因时遇到了问题.所有配置文件都与我们的应用程序的包名称匹配.我们使用TestFlight进行分发,虽然我
首先,我们正在开发一个目前使用
Swift / Xcode 6.1 GM 2进行开发的iOS应用程序.
在临时分发应用程序时,我们遇到了一些令人困惑的钥匙串访问问题,并且在跟踪原因时遇到了问题.所有配置文件都与我们的应用程序的包名称匹配.我们使用TestFlight进行分发,虽然我不认为这是问题所在. 我们只是设法让它在没有安装应用程序的iOS 7设备上运行.没有一个iOS 8设备是临时工作的.我们在开始时得到的错误是25300(errSecItemNotFound),现在重置供应配置文件后,我们得到一个普通的0(两者都在保存加载时仍然没有数据可以检索).从Xcode部署dev构建时,一切都很完美. 我已经分离了我们使用的keychain包装器的代码: import UIKit import Security let serviceIdentifier = "com.Test.KeychainTest" 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) var alertView = UIAlertView(); alertView.addButtonWithTitle("Ok"); alertView.title = "Status"; alertView.message = "Saving (status)"; alertView.show(); } 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,kCFBooleanTrue,kSecMatchLimitOneValue],kSecReturnDataValue,kSecMatchLimitValue]) var dataTypeRef :Unmanaged<AnyObject>? // Search for the keychain items let status: OSStatus = SecItemCopyMatching(keychainQuery,&dataTypeRef) var alertView = UIAlertView(); alertView.addButtonWithTitle("Ok"); alertView.title = "Status"; alertView.message = "Loading (status)"; alertView.show(); 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 } } >有什么我们可能错过的吗? 解决方法
供应配置文件和钥匙串代码中的所有内容似乎都很好.问题是Swift编译器中的设置…将“Release”的优化级别从“最快”更改为“无”,这似乎解决了问题
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |