Nivesh Singh Nivesh Singh - 1 month ago 14
iOS Question

how can i store my access token to defaults or into an array

i want to hit an API at login then i'll get a access token then whenever i"ll run my app it moves directly to homepage but m unable to get the access token there,how can i achieve homepage Conditions are not getting access token simply.


You can use user defaults objective c save your token

NSString *token = @“yourToken”;
[[NSUserDefaults standardUserDefaults] setObject: token forKey:@“Token”];
[[NSUserDefaults standardUserDefaults] synchronize]; 

Get your token

NSString *savedValue = [[NSUserDefaults standardUserDefaults]

Swift3.0 code save data

let defaults = UserDefaults.standard
defaults.set(“yourToken”, forKey: “Token”)

// Get the Token from UserDefaults
if let token = defaults.value(forKey: “Token”) as? String {
    print("defaults Token: \(token)")