Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Photo Browser iPhone App Connecting to an API using OAuth Connecting to Instagram

Benjamin Bell
Benjamin Bell
4,364 Points

Is there a better way than this to save data to keychain using SSKeychain pod or is this way ok?

    if (self.accessToken.length == 0){
        NSLog(@"Access token needs to be retrieved from memory");
        NSError *error = nil;
        self.accessToken = [SSKeychain passwordForService:@"Internet password" account:@"Instagram" error:&error];
        NSLog(@"Checking for errors whilst retrieving password");
        if ([error code] == errSecItemNotFound) {
            NSLog(@"Password not found");
            [SimpleAuth authorize:@"instagram" completion:^(NSDictionary *responseObject, NSError *error) {
                NSLog(@"Response: %@", responseObject);
                self.accessToken = responseObject[@"credentials"][@"token"];
                [SSKeychain setPassword:self.accessToken forService:@"Internet password" account:@"Instagram"];
                NSLog(@"Data saved to keychain");
                [self retrieveTag];
            }];
        } else if (error != nil) {
            NSLog(@"Some other error occurred: %@", [error localizedDescription]);
        } else {
            NSLog(@"Access token retrieved from memory");
            [self retrieveTag];
        }
    } else {
        NSLog(@"Access token already retrieved");
        [self retrieveTag];
    }

retrieveTag is just a simple method used to retrieve tag data from users account.

Any suggestions for improvement?

Thanks everyone

(sorry for all the NSLogs - just trying to debug this stuff)

1 Answer