Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma mark - UIWebViewDelegate
  2.  
  3. - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
  4.    
  5.     NSLog(@"%@", request);
  6.    
  7.     if([  [[request URL] description] rangeOfString:@"access_token="].location != NSNotFound){
  8.        
  9.         AVAccessToken *accsessToken = [[AVAccessToken alloc] init];
  10.        
  11.         NSString *query = [[request URL] description];
  12.        
  13.         NSArray *array = [query componentsSeparatedByString:@"#"];
  14.        
  15.         if([array count] > 1){
  16.             query = [array lastObject];
  17.         }
  18.        
  19.         NSArray *pairs = [query componentsSeparatedByString:@"&"];
  20.        
  21.         for(NSString *pair in pairs){
  22.            
  23.             NSArray *comp = [pair componentsSeparatedByString:@"="];
  24.            
  25.             if([[comp firstObject] isEqualToString:@"access_token"]){
  26.                
  27.                 accsessToken.token = [comp lastObject];
  28.             }else if([[comp firstObject] isEqualToString:@"user_id"]){
  29.                
  30.                 accsessToken.userID = [comp lastObject];
  31.             }else if([[comp firstObject] isEqualToString:@"expires_in"]){
  32.                
  33.                 NSTimeInterval interval = [[comp lastObject] doubleValue];
  34.                
  35.                 accsessToken.expirationDate = [NSDate dateWithTimeIntervalSinceNow:interval];
  36.             }
  37.         }
  38.        
  39.         self.webView.delegate = nil;
  40.        
  41.         if(self.completionBlock){
  42.             self.completionBlock(accsessToken);
  43.         }
  44.        
  45.         [self dismissViewControllerAnimated:YES completion:nil];
  46.        
  47.         return NO;
  48.     }
  49.    
  50.     return YES;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement