From 4381e22e63142e2597c1d9090c34df5e42198fbe Mon Sep 17 00:00:00 2001 From: ruqli Date: Tue, 31 May 2016 19:27:30 +0800 Subject: [PATCH] Should get parameter from NSURL query property. --- .../LIALinkedInAuthorizationViewController.m | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/IOSLinkedInAPI/LIALinkedInAuthorizationViewController.m b/IOSLinkedInAPI/LIALinkedInAuthorizationViewController.m index fdd5b26..7fa273e 100644 --- a/IOSLinkedInAPI/LIALinkedInAuthorizationViewController.m +++ b/IOSLinkedInAPI/LIALinkedInAuthorizationViewController.m @@ -95,7 +95,8 @@ - (void)tappedCancelButton:(id)sender { @implementation LIALinkedInAuthorizationViewController (UIWebViewDelegate) - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { - NSString *url = [[request URL] absoluteString]; + NSURL *requestURL = [request URL]; + NSString *url = [requestURL absoluteString]; //prevent loading URL if it is the redirectURL handlingRedirectURL = [url hasPrefix:self.application.redirectURL]; @@ -106,7 +107,7 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *) if (accessDenied) { self.cancelCallback(); } else { - NSString* errorDescription = [self extractGetParameter:@"error_description" fromURLString:url]; + NSString* errorDescription = [self extractGetParameter:@"error_description" fromURL:requestURL]; NSError *error = [[NSError alloc] initWithDomain:kLinkedInErrorDomain code:1 userInfo:@{ @@ -114,11 +115,11 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *) self.failureCallback(error); } } else { - NSString *receivedState = [self extractGetParameter:@"state" fromURLString: url]; + NSString *receivedState = [self extractGetParameter:@"state" fromURL: requestURL]; //assert that the state is as we expected it to be - if ([receivedState containsString:self.application.state]) { + if ([receivedState isEqualToString:self.application.state]) { //extract the code from the url - NSString *authorizationCode = [self extractGetParameter:@"code" fromURLString: url]; + NSString *authorizationCode = [self extractGetParameter:@"code" fromURL: requestURL]; self.successCallback(authorizationCode); } else { NSError *error = [[NSError alloc] initWithDomain:kLinkedInErrorDomain code:2 userInfo:[[NSMutableDictionary alloc] init]]; @@ -129,9 +130,9 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *) return !handlingRedirectURL; } -- (NSString *)extractGetParameter: (NSString *) parameterName fromURLString:(NSString *)urlString { +- (NSString *)extractGetParameter: (NSString *) parameterName fromURL:(NSURL *)url { NSMutableDictionary *mdQueryStrings = [[NSMutableDictionary alloc] init]; - urlString = [[urlString componentsSeparatedByString:@"?"] objectAtIndex:1]; + NSString *urlString = url.query; for (NSString *qs in [urlString componentsSeparatedByString:@"&"]) { [mdQueryStrings setValue:[[[[qs componentsSeparatedByString:@"="] objectAtIndex:1] stringByReplacingOccurrencesOfString:@"+" withString:@" "]