Skip to content

Instantly share code, notes, and snippets.

View keithelliott's full-sized avatar

Keith Elliott keithelliott

View GitHub Profile
#import "FoursquareAuthentication.h"
// 5. setup some helpers so we don't have to hard-code everything
#define FOURSQUARE_AUTHENTICATE_URL @"https://foursquare.com/oauth2/authorize"
#define FOURSQUARE_CLIENT_ID @"YOUR CLIENT ID"
#define FOURSQUARE_CLIENT_SECRET @"YOUR CLIENT SECRET"
#define FOURSQUARE_REDIRECT_URI @"ios-app://redirect"
@interface FoursquareAuthentication ()
#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];
#import "ViewController.h"
#import "FoursquareAuthentication.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];