Created
April 19, 2013 00:25
-
-
Save keithelliott/5417251 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 () | |
// 1. create webview property | |
@property (nonatomic, strong) UIWebView *webView; | |
@end | |
@implementation FoursquareAuthentication | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view. | |
// initialize the webview and add it to the view | |
//2. init with the available window dimensions | |
self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)]; | |
//3. set the delegate to self so that we can respond to web activity | |
self.webView.delegate = self; | |
//4. add the webview to the view | |
[self.view addSubview:self.webView]; | |
//6. Create the authenticate string that we will use in our request to foursquare | |
// we have to provide our client id and the same redirect uri that we used in setting up our app | |
// The redirect uri can be any scheme we want it to be... it's not actually going anywhere as we plan to | |
// intercept it and get the access token off of it | |
NSString *authenticateURLString = [NSString stringWithFormat:@"%@?client_id=%@&response_type=token&redirect_uri=%@", FOURSQUARE_AUTHENTICATE_URL, FOURSQUARE_CLIENT_ID, FOURSQUARE_REDIRECT_URI]; | |
//7. Make the request and load it into the webview | |
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:authenticateURLString]]; | |
[self.webView loadRequest:request]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment