Skip to content

Instantly share code, notes, and snippets.

@keithelliott
Created April 19, 2013 00:27
Show Gist options
  • Save keithelliott/5417258 to your computer and use it in GitHub Desktop.
Save keithelliott/5417258 to your computer and use it in GitHub Desktop.
#pragma mark - Web view delegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if([request.URL.scheme isEqualToString:@"ios-app"]){
// 8. get the url and check for the access token in the callback url
NSString *URLString = [[request URL] absoluteString];
if ([URLString rangeOfString:@"access_token="].location != NSNotFound) {
// 9. Store the access token in the user defaults
NSString *accessToken = [[URLString componentsSeparatedByString:@"="] lastObject];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:accessToken forKey:@"access_token"];
[defaults synchronize];
// 10. dismiss the view controller
[self dismissViewControllerAnimated:YES completion:nil];
}
}
return YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment