使用Mailcore 2下载iOS附件

时间:2016-05-07 16:31:52

标签: ios objective-c mailcore2

我正在开发一个简单的多媒体浏览器iOS应用程序,在那里我使用我的电子邮件帐户登录,我只看到了所有附件......我正在使用obj c和Mailcore2框架。

我刚遇到问题。我可以下载我的电子邮件并在控制台中查看它们,但我看不到下载的附件..

这是我的loademails方法:

(void)loadEmails
{
 MCOIMAPMessagesRequestKind requestKind = (MCOIMAPMessagesRequestKind)
(MCOIMAPMessagesRequestKindHeaders | MCOIMAPMessagesRequestKindStructure |
 MCOIMAPMessagesRequestKindInternalDate | MCOIMAPMessagesRequestKindHeaderSubject |
 MCOIMAPMessagesRequestKindFlags);

MCOIndexSet *uidSet = [MCOIndexSet indexSetWithRange:MCORangeMake(1,UINT64_MAX)];//for all msgs

self.imapMessagesFetchOp = [self.imapSession fetchMessagesByUIDOperationWithFolder:@"INBOX"
                                                                       requestKind:requestKind
                                                                                uids:uidSet];




__weak MasterViewController *weakSelf = self;
[self.imapMessagesFetchOp start:^(NSError *error, NSArray *messages, MCOIndexSet *vanishedMessages) {
    MasterViewController *strongSelf = weakSelf;

NSLog(@"All emails fetched.");


strongSelf.messages = messages;

MCOIMAPMessage *msg = [messages lastObject];
MCOIMAPPart *part = [msg.attachments lastObject];

   MCOIMAPFetchContentOperation *mcop = [self.imapSession fetchMessageAttachmentOperationWithFolder:@"INBOX" uid:msg.uid partID:part.partID encoding:part.encoding];



    [mcop start:^(NSError *error, NSData *data) {
        if (error != nil) {
            NSLog(@"error:%@", error);
            return;
        }
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *saveDirectory = [paths objectAtIndex:0];
    NSString *attachmentPath = [saveDirectory stringByAppendingPathComponent:part.filename];
    [data writeToFile:attachmentPath atomically:YES];

    }];
[strongSelf rebuildSenderArray];
[strongSelf.tableView reloadData];
NSLog(@"%lu emails fetched", (unsigned long)strongSelf.messages.count);

}];
}

对我有什么建议吗?谢谢

0 个答案:

没有答案