Hi, I’m trying to save data to the iOS keychain. I...
# multiplatform
r
Hi, I’m trying to save data to the iOS keychain. I use the following piece of code to accomplish that:
Copy code
val searchDictionary = CFDictionaryCreateMutable(kCFAllocatorDefault, 5, null, null)

        CFDictionaryAddValue(searchDictionary, kSecClass, kSecClassGenericPassword)
        CFDictionaryAddValue(searchDictionary, kSecAttrService, CFBridgingRetain(appName))
        CFDictionaryAddValue(searchDictionary, kSecAttrGeneric, CFBridgingRetain(identifier))
        CFDictionaryAddValue(searchDictionary, kSecAttrAccount, CFBridgingRetain(identifier))
        CFDictionaryAddValue(searchDictionary, kSecValueData, CFBridgingRetain(NSNumber(int = 2048)))

 SecItemAdd(searchDictionary, null)
But I keep getting OSStatus -50 (One or more parameters passed to a function were not valid.). I followed several Ojective-c tutorials to come up with this code and it should be valid.. Someone got an idea what I’m missing?
k
is there a reason your 5th add statement uses
dictionary
and not
searchDictionary
r
Ah damn, updated the code snipped. In my source it uses the same dictionary.
k
i'm not sure that
NSNumber
is valid for
kSecValueData
it's expecting type CFData
r
Ah hero 🙌! Wrapping my value in NSData seems to do the trick 😄.
245 Views