2013-03-21 97 views
-2

我使用MailCore建立我的電子郵件客戶端,跑進一個小問題,同時儘量使用IMAP的電子郵件帳戶接收郵件。MailCore IMAP服務器導致應用程序崩潰?

下面是代碼我在我viewDidLoad中此:

CTCoreAccount *account = [[CTCoreAccount alloc] init]; 
     BOOL success = [account connectToServer:@"imap.mail.me.com" 
              port:993 
           connectionType:CTConnectionTypePlain 
             authType:CTImapAuthTypePlain 
              login:[keychain objectForKey:(__bridge id)kSecAttrAccount] 
             password:[keychain objectForKey:(__bridge id)kSecValueData]]; 
     if (!success) { 

      UIAlertView *alertView1 = [[UIAlertView alloc] initWithTitle:@"Error Checking Email" message:@"There was a problem checking your inbox, please try again later." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
      [alertView1 show]; 

     } 


     CTCoreFolder *inbox = [account folderWithPath:@"INBOX"]; 
     messages = [inbox messagesFromSequenceNumber:1 to:0 withFetchAttributes:CTFetchAttrEnvelope]; 
     [tableView reloadData]; 

問題是,當我跑我的應用程序,它不會啓動和我的手機顯示黑屏。我試着評論這些代碼,並且一切正常。

謝謝!

回答

1

阻止主(UI)線程連接和下載信息時,它可以輕鬆拍攝長於時間允許啓動您的應用程序(約20秒,我認爲)。

它看起來像MailCore沒有一個異步API,所以你必須在後臺自己使用它。我建議使用調度隊列(dispatch_async()是相當簡單的正確使用提供你只用給UIKit類弱引用)或NSOperationQueue使事情在後臺運行。

通常併發警告適用。

+0

@ranjha正如我所說,這可能是阻塞主線程,並可能是對App Store的拒絕理由。 – 2013-03-22 23:27:20