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:
- + (void)dismiss
- {
- #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_4_3
- UIViewController *theViewController = [sharedDialog presentingViewController];
- [theViewController dismissModalViewControllerAnimated:YES];
- #else
- UIViewController *theViewController = [sharedDialog parentViewController];
- [theViewController dismissModalViewControllerAnimated:YES];
- #endif
- }
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:
- + (void)dismiss
- {
- #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_4_3
- if ([sharedDialog respondsToSelector:@selector(presentingViewController)])
- {
- UIViewController *theViewController = [sharedDialog presentingViewController];
- [theViewController dismissModalViewControllerAnimated:YES];
- }
- else
- {
- UIViewController *theViewController = [sharedDialog parentViewController];
- [theViewController dismissModalViewControllerAnimated:YES];
- }
- #else
- UIViewController *theViewController = [sharedDialog parentViewController];
- [theViewController dismissModalViewControllerAnimated:YES];
- #endif
- }
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
- [[self presentingController] presentModalViewController:self animated:YES];
To:
- UIViewController *theController = [self presentingController];
- #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_4_3
- SEL theSelector = NSSelectorFromString(@"presentModalViewController:animated:");
- NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature:[[theController class] instanceMethodSignatureForSelector:theSelector]];
- [anInvocation setSelector:theSelector];
- [anInvocation setTarget:theController];
- BOOL anim = YES;
- UIViewController *val = self;
- [anInvocation setArgument:&val atIndex:2];
- [anInvocation setArgument:&anim atIndex:3];
- [anInvocation performSelector:@selector(invoke) withObject:nil afterDelay:1];
- #else
- [theController presentModalViewController:self animated:YES];
- #endif
Now it can run normally, and my problem is also solved. No problems have been found in other aspects of ASIHttpRequest.