該博客主要描述我所遇到的問題情況。配置環(huán)境我附上連接自己去看看。
Mailcore2的配置
-
https://github.com/MailCore/mailcore2/ 在該網(wǎng)址中 查找 Build for iOS/OSX該選項(xiàng)里面有對iOS的配置過程和視頻。
https://github.com/MailCore/mailcore2/blob/master/build-mac/README.md 該連接是 Build for iOS/OSX 跳轉(zhuǎn)后的連接。 大概iOS的內(nèi)容如下:
For iOS - If you're targeting iOS, you have to link against MailCore 2 as a static library:
1.Add libMailCore-ios.a
2.Add CFNetwork.framework
3.Add Security.framework
4.Set 'Other Linker Flags': -lctemplate-ios -letpan-ios -lxml2 -lsasl2 -liconv -ltidy -lz -lc++ -lresolv -stdlib=libc++ -ObjC
5.Make sure to use LLVM C++ standard library. Open Build Settings, scroll down to 'C++ Standard Library', and select libc++.
6.In Build Phases, add a Target Dependency of static mailcore2 ios.
該視頻是iOS配置的視頻 不過有些地方和官方代碼不一樣,還是以官方的代碼配置為主,具體那里不同自己看后對比就知道
遇到的坑
- Error Domain=MCOErrorDomain Code=5 "Unable to authenticate with the current session's credentials." UserInfo={NSLocalizedDescription=Unable to authenticate with the current session's credentials.}
這個錯誤主要是郵箱帳號或者密碼錯誤。郵箱后綴是否正確。如163郵箱密碼是使用授權(quán)碼而不是登錄密碼(這個只是針對hostname:imap.163.com,當(dāng)hostname:appleimap.163.com用郵箱登錄密碼依然可以使用)。 - Error Domain=MCOErrorDomain Code=4 "The certificate for this server is invalid." UserInfo={NSLocalizedDescription=The certificate for this server is invalid.}
服務(wù)器證書無效,可以將checkCertificateEnabled 設(shè)置為NO,即session.checkCertificateEnabled = NO; - Error Domain=MCOErrorDomain Code=1 "A stable connection to the server could not be established." UserInfo={NSLocalizedDescription=A stable connection to the server could not be established.}
這個錯誤可以從以下三個方面嘗試解決:
1.hostname不存在,或者拼寫錯誤,修改hostname;該hostname不一定是 imap.**.com,我項(xiàng)目中用到的hostname是 10.101.10.1(主機(jī)名)。
2.需要SSL安全鏈接,將connectionType設(shè)置為MCOConnectionTypeTLS;
3.端口號錯誤。
以上解決后就可以跑起代碼了。
附加其他情況:
unzip: cannot find zipfile directory in one of ctemplate-osx-3.zip or
ctemplate-osx-3.zip.zip, and cannot find ctemplate-osx-3.zip.ZIP, period.
/Users/somewhere/mailcore2-0.6.2/scripts/include.sh/build-dep.sh: line 329: cd: ctemplate-osx-3: No such file or directory
找不到'libetpan / libetpan.h'文件
找不到'unicode / udat.h'文件
找不到'ctemplate / template.h'文件
該問題是應(yīng)該你導(dǎo)入的mailcore2中的libMailCore-ios.a為紅色沒有導(dǎo)入成功。
解決方法:
1.先運(yùn)行 static mailcore2 ios
- 再運(yùn)行 mailcore2 ios
3.再選擇你自己的schemes的項(xiàng)目進(jìn)行運(yùn)行。
最后libMailCore-ios.a 庫就導(dǎo)入進(jìn)來了。(如果還是不行的話,用4g進(jìn)行 下載libMailCore-ios.a)
解決中文名字的文件夾亂碼問題
[[imapSession defaultNamespace] componentsFromPath:folder.path])
問題:如何添加正文附件
for (NHLineAttachment *lineAttachment in lineAttachmentArray) {
MCOAttachment *attachment = [MCOAttachment attachmentWithContentsOfFile:lineAttachment.attach_localfile];
attachment.contentID = lineAttachment.attach_contentID;
[attachment setInlineAttachment:YES];
[messageBuilder addRelatedAttachment:attachment];
}