Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma mark - UIWebViewDelegate
- - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
- NSLog(@"%@", request);
- if([ [[request URL] description] rangeOfString:@"access_token="].location != NSNotFound){
- AVAccessToken *accsessToken = [[AVAccessToken alloc] init];
- NSString *query = [[request URL] description];
- NSArray *array = [query componentsSeparatedByString:@"#"];
- if([array count] > 1){
- query = [array lastObject];
- }
- NSArray *pairs = [query componentsSeparatedByString:@"&"];
- for(NSString *pair in pairs){
- NSArray *comp = [pair componentsSeparatedByString:@"="];
- if([[comp firstObject] isEqualToString:@"access_token"]){
- accsessToken.token = [comp lastObject];
- }else if([[comp firstObject] isEqualToString:@"user_id"]){
- accsessToken.userID = [comp lastObject];
- }else if([[comp firstObject] isEqualToString:@"expires_in"]){
- NSTimeInterval interval = [[comp lastObject] doubleValue];
- accsessToken.expirationDate = [NSDate dateWithTimeIntervalSinceNow:interval];
- }
- }
- self.webView.delegate = nil;
- if(self.completionBlock){
- self.completionBlock(accsessToken);
- }
- [self dismissViewControllerAnimated:YES completion:nil];
- return NO;
- }
- return YES;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement