Problem and Solution of ASIHttpRequest library after upgrading to iOS5

Source: Internet
Author: User

I tried to upgrade the official version of iOS5. The latest Xcode version is about GB, which is much smaller than the previous installation package.

After upgrading Xcode, open the previously created project. If you are lucky, there is no error, and the program can run properly. Because the ASIHttpRequest library is used in my program, I found a small problem:

The ASIAuthenticationDialog built-in dialog box appears when there is a proxy on the network. Then, you cannot dismiss it whether you click "cancle" or "login. There is no problem in SDK 4.3. In SDK 5.0, the output is displayed in the Console:

Unbalanced callto begin/end appearance transitions for <ASIAutorotatingViewController:>

It is clearly displayed that there is a problem with this library in sdk5, and there will be exceptions in the program when the tuning is stopped.

Therefore, it is clearly indicated that the changes in SDK5 affect the normal use of ASIHttpRequest. So I want to fix this problem. After my research, I found that dismiss does not work because the parentViewController of UIViewController no longer returns the correct value. The returned value is nil, which is replaced by presentingViewController in SDK5. So in ASIAuthenticationDialog. m, find the + (void) dismiss method and modify it:

 
 
  1. + (void)dismiss   
  2. {   
  3. #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_4_3    
  4.     UIViewController *theViewController = [sharedDialog presentingViewController];   
  5.     [theViewController dismissModalViewControllerAnimated:YES];   
  6. #else    
  7.     UIViewController *theViewController = [sharedDialog parentViewController];   
  8.     [theViewController dismissModalViewControllerAnimated:YES];   
  9. #endif    
  10. }   

In this way, the compiled program can run correctly on the ios5 device, but the devices below ios5 will crash. Because it is a library, it is necessary to consider compatibility with different versions, so further modification:

 
 
  1. + (void)dismiss   
  2. {   
  3. #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_4_3    
  4.     if ([sharedDialog respondsToSelector:@selector(presentingViewController)])    
  5.     {   
  6.         UIViewController *theViewController = [sharedDialog presentingViewController];   
  7.         [theViewController dismissModalViewControllerAnimated:YES];   
  8.     }   
  9.     else   
  10.     {   
  11.         UIViewController *theViewController = [sharedDialog parentViewController];   
  12.         [theViewController dismissModalViewControllerAnimated:YES];   
  13.     }   
  14. #else    
  15.     UIViewController *theViewController = [sharedDialog parentViewController];   
  16.     [theViewController dismissModalViewControllerAnimated:YES];   
  17. #endif    
  18. }   

There is also the Console error prompt above. The solution is to find the-(void) show method in ASIAuthenticationDialog. m, and put the last line of code

 
 
  1. [[self presentingController] presentModalViewController:self animated:YES];   

To:

 
 
  1. UIViewController *theController = [self presentingController];   
  2. #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_4_3    
  3.     SEL theSelector = NSSelectorFromString(@"presentModalViewController:animated:");   
  4.     NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature:[[theController class] instanceMethodSignatureForSelector:theSelector]];   
  5.     [anInvocation setSelector:theSelector];   
  6.     [anInvocation setTarget:theController];         
  7.     BOOL               anim = YES;   
  8.     UIViewController   *val = self;   
  9.     [anInvocation setArgument:&val atIndex:2];   
  10.     [anInvocation setArgument:&anim atIndex:3];   
  11.     [anInvocation performSelector:@selector(invoke) withObject:nil afterDelay:1];   
  12. #else          
  13.     [theController presentModalViewController:self animated:YES];   
  14. #endif   

Now it can run normally, and my problem is also solved. No problems have been found in other aspects of ASIHttpRequest.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.