https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
r

Ronald van D

02/13/2020, 3:23 PM
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

Kris Wong

02/13/2020, 3:29 PM
is there a reason your 5th add statement uses
dictionary
and not
searchDictionary
r

Ronald van D

02/13/2020, 3:32 PM
Ah damn, updated the code snipped. In my source it uses the same dictionary.
k

Kris Wong

02/13/2020, 3:37 PM
i'm not sure that
NSNumber
is valid for
kSecValueData
it's expecting type CFData
r

Ronald van D

02/13/2020, 3:53 PM
Ah hero 🙌! Wrapping my value in NSData seems to do the trick 😄.
95 Views