Iphone MailCore IMAP服务器导致应用程序崩溃?
我正在使用MailCore构建我的电子邮件客户端,在尝试使用IMAP从电子邮件帐户接收邮件时遇到了一个小问题 以下是我在viewDidLoad中为此提供的代码:Iphone MailCore IMAP服务器导致应用程序崩溃?,iphone,sdk,mailcore,Iphone,Sdk,Mailcore,我正在使用MailCore构建我的电子邮件客户端,在尝试使用IMAP从电子邮件帐户接收邮件时遇到了一个小问题 以下是我在viewDidLoad中为此提供的代码: CTCoreAccount *account = [[CTCoreAccount alloc] init]; BOOL success = [account connectToServer:@"imap.mail.me.com" por
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];
问题是当我运行我的应用程序时,它不会启动,我的手机会显示空白的黑屏。我试着注释代码,一切正常
谢谢 这会阻止连接和下载消息的主(UI)线程,这很容易会花费比允许启动应用程序的时间更长的时间(我想大约20秒)
看起来MailCore没有异步API,所以您必须自己在后台使用它。我建议使用分派队列(dispatch\u async()
非常容易正确使用,前提是您只使用对UIKit类的弱引用)或NSOperationQueue
在后台运行
通常的并发警告适用。@ranjha正如我所说,它可能阻塞了主线程,可能是应用商店拒绝的理由。