gpt4 book ai didi

swift - 如何在 swift 中使用 MCOIMAPSession mailcore

转载 作者:可可西里 更新时间:2023-11-01 02:17:21 26 4
gpt4 key购买 nike

大家好,我想在我的 swift 项目中使用 MCOImapSession。我可以将 #import <MailCore/MailCore.h> 添加到头文件中,我想像这样快速使用此代码 question

请指导我。

        MCOIMAPSession *session = [[MCOIMAPSession alloc] init];
[session setHostname:@"imap.gmail.com"];
[session setPort:993];
[session setUsername:@"ADDRESS@gmail.com"];
[session setPassword:@"123456"];
[session setConnectionType:MCOConnectionTypeTLS];

MCOIMAPMessagesRequestKind requestKind = MCOIMAPMessagesRequestKindHeaders;
NSString *folder = @"INBOX";
MCOIndexSet *uids = [MCOIndexSet indexSetWithRange:MCORangeMake(1, UINT64_MAX)];

MCOIMAPFetchMessagesOperation *fetchOperation = [session fetchMessagesOperationWithFolder:folder requestKind:requestKind uids:uids];

[fetchOperation start:^(NSError * error, NSArray * fetchedMessages, MCOIndexSet * vanishedMessages) {
//We've finished downloading the messages!

//Let's check if there was an error:
if(error) {
NSLog(@"Error downloading message headers:%@", error);
}

//And, let's print out the messages...
NSLog(@"The post man delivereth:%@", fetchedMessages);
}];

我在谷歌搜索太多,我得到了这段代码:

let imapsession = MCOIMAPSession()
imapsession.hostname = ""
imapsession.port = 123
imapsession.username = ""
imapsession.password = ""
imapsession.connectionType = MCOConnectionType.TLS

let requestKind : MCOIMAPMessagesRequestKind = MCOIMAPMessagesRequestKind.Headers

let folder : String = "INBOX"
let uids : MCOIndexSet = MCOIndexSet(range: MCORangeMake(1, UINT64_MAX))

let fetchOperation : MCOIMAPFetchMessagesOperation = imapsession.fetchMessagesOperationWithFolder(folder, requestKind: requestKind, uids: uids)

fetchOperation.start({ (err: NSError!, fetchedMessages: [AnyObject]!, indexSet: MCOIndexSet!) -> Void in

if err != nil {
println("Error downloading message headers: \(err)")
}

println("Inbox contains \(fetchedMessages.count) emails.")

let msgs = fetchedMessages as [MCOIMAPMessage]


})

但是当运行这个时,我在这行中遇到了很多错误:

fetchOperation.start({ (err: NSError!, fetchedMessages: [AnyObject]!, indexSet: MCOIndexSet!) -> Void in

if err != nil {
println("Error downloading message headers: \(err)")
}

println("Inbox contains \(fetchedMessages.count) emails.")

let msgs = fetchedMessages as [MCOIMAPMessage]


})

请帮助我,我很困惑,很累!!! enter image description here

最佳答案

let imapsession = MCOIMAPSession()
imapsession.hostname = ""
imapsession.port = 123
imapsession.username = ""
imapsession.password = ""
imapsession.connectionType = MCOConnectionType.TLS

let requestKind : MCOIMAPMessagesRequestKind = MCOIMAPMessagesRequestKind.Headers

let folder : String = "INBOX"
let uids : MCOIndexSet = MCOIndexSet(range: MCORangeMake(1, UINT64_MAX))

let fetchOperation : MCOIMAPFetchMessagesOperation = imapsession.fetchMessagesOperationWithFolder(folder, requestKind: requestKind, uids: uids)

fetchOperation.start { (err, msg, vanished) -> Void in
print("error from server \(err)")
print("fetched \(msg?.count) messages")
}

关于swift - 如何在 swift 中使用 MCOIMAPSession mailcore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35989946/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com