It is possible to store a NSDictionary
in the iPhone
keychain, using KeychainItemWrapper
(or without)?
If it's not possible, have you another solution?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
Encoding :
[dic description]
Decoding :
[dic propertyList]
I found that the keychain wrapper only wants strings. Not even NSData. So to store a dictionary you'll have to do as Bret suggested, but with an extra step to convert the NSData serialization to a string. Like this:
Reading it back:
Using the
KeychainItemWrapper
dependency requires modifying the library/sample code to acceptNSData
as the encrypted payload, which is not future proof. Also, doing theNSDictionary > NSData > NSString
conversion sequence just so that you can useKeychainItemWrapper
is inefficient:KeychainItemWrapper
will convert your string back toNSData
anyway, to encrypt it.Here's a complete solution that solves the above by utilizing the keychain library directly. It is implemented as a category so you use it like this:
and here's the Category:
In fact, you can modify it easily to store any kind of serializable object in the keychain, not just a dictionary. Just make an
NSData
representation of the object you want to store.Made few minor changes to Dts category. Converted to ARC and using NSKeyedArchiver to store custom objects.
You must properly serialize the
NSDictionary
before storing it into the Keychain. Using:you will end up with a
NSDictionary
collection of onlyNSString
objects. If you want to maintain the data types of the objects, you can useNSPropertyListSerialization
.The
NSDictionary
returned by the second call toNSPropertyListSerialization
will maintain original data types within theNSDictionary
collection.You can store anything, you just need to serialize it.
You should be able to store that data in the keychain.