3
votes

iOS : NSHTTPCookieStorage, Keychain, NSUserDefault between these three, what is the best place to store token on device? and why?

Note: I don't want to share token with any other app or Safari/browser.

1

1 Answers

1
votes

NSUserDefault, data stored in the it will remain as it is till the application is there. Once you delete the application everything will be lost. Not fully secured.

Keychain, data stored in it will remain as it till the user reset the entire phone settings. Refer this link for more info along with implementation. If user do backup of that iPhone & re-store any other phone with it all data will be available to that device. Also all the data are stored securely & in encrypted format.

NSHTTPCookieStorage implements a singleton object (shared instance) that manages storage of cookies. Each cookie is represented by an instance of the NSHTTPCookie class. As a rule, cookies are shared among all applications and are kept in sync across process boundaries. Session cookies (where the cookie object’s isSessionOnly method returns YEStrue) are local to a single process and are not shared.

If you would like to store token use in Application as well as in Safari browser or in any other app then NSHTTPCookieStorage is better option for you.