歡迎您光臨本站 註冊首頁

升級到iOS5后ASIHttpRequest庫問題及解決方法

←手機掃碼閱讀     火星人 @ 2014-03-12 , reply:0
  

由於正式版的iOS5出來了,所以我也試著去升級了。於是下載了最新的Xcode,才1.7G左右,比以往的安裝包要小許多。

升級Xcode后,打開以前創建的工程, 運氣好,一個錯誤都沒有,程序也能正常跑起來。由於我程序中用了ASIHttpRequest這個庫,讓我發現了一個小問題,就是

ASIAuthenticationDialog這個內置對話框在網路有代理的情況下出現,然後無論點cancle或是login都不能dismiss。在4.3的SDK中完全沒問題,在5.0的SDK中就會在Console中看到輸出:

Unbalanced calls to begin/end appearance transitions for

很明顯示在sdk5中, 用這個庫有問題,還有在停止調式的時候,程序會有異常產生。

於是很明顯示是SDK5的變化影響了ASIHttpRequest的正常使用。於是我要fix這個問題,經過我研究發現,dismiss不起作用是由於UIViewController的parentViewController不再返回正確值了,返回的是nil,而在SDK5中被presentingViewController取代了。於是在ASIAuthenticationDialog.m中找到+(void)dismiss這個方法並修改為:

  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. }  
還有上面那個Console的錯誤提示,解決方法是,在ASIAuthenticationDialog.m中找到-(void)show這個方法,並把最後一行代碼
  1. [[self presentingController] presentModalViewController:self animated:YES];  
修改為:
  1. UIViewController *theController = [self presentingController];  
  2.       
  3. #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_4_3   
  4.     SEL theSelector = NSSelectorFromString(@"presentModalViewController:animated:");  
  5.     NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature:[[theController class] instanceMethodSignatureForSelector:theSelector]];  
  6.       
  7.     [anInvocation setSelector:theSelector];  
  8.     [anInvocation setTarget:theController];  
  9.       
  10.     BOOL               anim = YES;  
  11.     UIViewController   *val = self;  
  12.     [anInvocation setArgument:&val atIndex:2];  
  13.     [anInvocation setArgument:&anim atIndex:3];  
  14.       
  15.     [anInvocation performSelector:@selector(invoke) withObject:nil afterDelay:1];  
  16. #else   
  17.       
  18.     [theController presentModalViewController:self animated:YES];  
  19. #endif  
這下就可以正常運行了喲, 我的問題也解決了。關於ASIHttpRequest的其它方面,到目前為止還沒發現問題。


[火星人 ] 升級到iOS5后ASIHttpRequest庫問題及解決方法已經有200次圍觀

http://coctec.com/docs/linux/show-post-65356.html