我有收集视图,用户可以下载epub文件并在下载完成后显示。我使用FolioReaderKit打开epub文件,我也得到正确的路径和epub文件。我正在使用Alamofire下载,但我得到了这一堆错误,
2016-11-04 18:02:28.304 indodragon[9482:74592] [SSZipArchive] Error: The file “EPUB.epub” couldn’t be saved in the folder “Documents” because a file with the same name already exists.
2016-11-04 18:02:28.305 indodragon[9482:74592] [SSZipArchive] Error: The file “EPUB.epub” couldn’t be saved in the folder “Documents” because a file with the same name already exists.
2016-11-04 18:02:28.306 indodragon[9482:74592] [SSZipArchive] Error: The file “EPUB.epub” couldn’t be saved in the folder “Documents”.
2016-11-04 18:02:28.320 indodragon[9482:74592] [SSZipArchive] Error: The file “EPUB.epub” couldn’t be saved in the folder “Documents”.
2016-11-04 18:02:28.321 indodragon[9482:74592] [SSZipArchive] Error: The file “EPUB.epub” couldn’t be saved in the folder “Documents”.
2016-11-04 18:02:28.322 indodragon[9482:74592] [SSZipArchive] Error: The file “EPUB.epub” couldn’t be saved in the folder “Documents”.
2016-11-04 18:02:28.322 indodragon[9482:74592] [SSZipArchive] Error: The file “EPUB.epub” couldn’t be saved in the folder “Documents”.
2016-11-04 18:02:28.323 indodragon[9482:74592] [SSZipArchive] Error: The file “EPUB.epub” couldn’t be saved in the folder “Documents”.
2016-11-04 18:02:28.324 indodragon[9482:74592] [SSZipArchive] Error: The file “EPUB.epub” couldn’t be saved in the folder “Documents”.
2016-11-04 18:02:28.325 indodragon[9482:74592] [SSZipArchive] Error: The file “EPUB.epub” couldn’t be saved in the folder “Documents”.
2016-11-04 18:02:28.326 indodragon[9482:74592] [SSZipArchive] Error: The file “EPUB.epub” couldn’t be saved in the folder “Documents”.
2016-11-04 18:02:28.328 indodragon[9482:74592] [SSZipArchive] Error: The file “EPUB.epub” couldn’t be saved in the folder “Documents”.
2016-11-04 18:02:28.329 indodragon[9482:74592] [SSZipArchive] Error: The file “EPUB.epub” couldn’t be saved in the folder “Documents”.
2016-11-04 18:02:28.330 indodragon[9482:74592] [SSZipArchive] Error: The file “EPUB.epub” couldn’t be saved in the folder “Documents”.
2016-11-04 18:02:28.331 indodragon[9482:74592] [SSZipArchive] Error: The file “EPUB.epub” couldn’t be saved in the folder “Documents” because a file with the same name already exists.
2016-11-04 18:02:28.332 indodragon[9482:74592] [SSZipArchive] Error: The file “EPUB.epub” couldn’t be saved in the folder “Documents”.
2016-11-04 18:02:28.332 indodragon[9482:74592] [SSZipArchive] Error: The file “EPUB.epub” couldn’t be saved in the folder “Documents”.
2016-11-04 18:02:28.333 indodragon[9482:74592] [SSZipArchive] Set attributes failed for directory: /Users/crocodic/Library/Developer/CoreSimulator/Devices/C8DC5F44-B2FC-4FC3-8E10-B87FC00791FA/data/Containers/Data/Application/2ABE6535-FE74-4F4D-AC2C-B19C85AD94C0/Documents/EPUB.epub/OEBPS/assets/themetamorphosis_1200x1600.jpg.
2016-11-04 18:02:28.333 indodragon[9482:74592] [SSZipArchive] Error setting directory file modification date attribute: The file “themetamorphosis_1200x1600.jpg” couldn’t be saved in the folder “assets”.
2016-11-04 18:02:28.334 indodragon[9482:74592] [SSZipArchive] Set attributes failed for directory: /Users/crocodic/Library/Developer/CoreSimulator/Devices/C8DC5F44-B2FC-4FC3-8E10-B87FC00791FA/data/Containers/Data/Application/2ABE6535-FE74-4F4D-AC2C-B19C85AD94C0/Documents/EPUB.epub/OEBPS/front-cover.html.
2016-11-04 18:02:28.334 indodragon[9482:74592] [SSZipArchive] Error setting directory file modification date attribute: The file “front-cover.html” couldn’t be saved in the folder “OEBPS”.
2016-11-04 18:02:28.334 indodragon[9482:74592] [SSZipArchive] Set attributes failed for directory: /Users/crocodic/Library/Developer/CoreSimulator/Devices/C8DC5F44-B2FC-4FC3-8E10-B87FC00791FA/data/Containers/Data/Application/2ABE6535-FE74-4F4D-AC2C-B19C85AD94C0/Documents/EPUB.epub/OEBPS/chapter-003-chapter-iii.html.
2016-11-04 18:02:28.335 indodragon[9482:74592] [SSZipArchive] Error setting directory file modification date attribute: The file “chapter-003-chapter-iii.html” couldn’t be saved in the folder “OEBPS”.
2016-11-04 18:02:28.335 indodragon[9482:74592] [SSZipArchive] Set attributes failed for directory: /Users/crocodic/Library/Developer/CoreSimulator/Devices/C8DC5F44-B2FC-4FC3-8E10-B87FC00791FA/data/Containers/Data/Application/2ABE6535-FE74-4F4D-AC2C-B19C85AD94C0/Documents/EPUB.epub/toc.ncx.
2016-11-04 18:02:28.335 indodragon[9482:74592] [SSZipArchive] Error setting directory file modification date attribute: The file “toc.ncx” couldn’t be saved in the folder “EPUB.epub”.
2016-11-04 18:02:28.336 indodragon[9482:74592] [SSZipArchive] Set attributes failed for directory: /Users/crocodic/Library/Developer/CoreSimulator/Devices/C8DC5F44-B2FC-4FC3-8E10-B87FC00791FA/data/Containers/Data/Application/2ABE6535-FE74-4F4D-AC2C-B19C85AD94C0/Documents/EPUB.epub/OEBPS/chapter-001-chapter-i.html.
2016-11-04 18:02:28.336 indodragon[9482:74592] [SSZipArchive] Error setting directory file modification date attribute: The file “chapter-001-chapter-i.html” couldn’t be saved in the folder “OEBPS”.
2016-11-04 18:02:28.336 indodragon[9482:74592] [SSZipArchive] Set attributes failed for directory: /Users/crocodic/Library/Developer/CoreSimulator/Devices/C8DC5F44-B2FC-4FC3-8E10-B87FC00791FA/data/Containers/Data/Application/2ABE6535-FE74-4F4D-AC2C-B19C85AD94C0/Documents/EPUB.epub/mimetype.
2016-11-04 18:02:28.337 indodragon[9482:74592] [SSZipArchive] Error setting directory file modification date attribute: The file “mimetype” couldn’t be saved in the folder “EPUB.epub”.
2016-11-04 18:02:28.337 indodragon[9482:74592] [SSZipArchive] Set attributes failed for directory: /Users/crocodic/Library/Developer/CoreSimulator/Devices/C8DC5F44-B2FC-4FC3-8E10-B87FC00791FA/data/Containers/Data/Application/2ABE6535-FE74-4F4D-AC2C-B19C85AD94C0/Documents/EPUB.epub/OEBPS/chapter-002-chapter-ii.html.
2016-11-04 18:02:28.337 indodragon[9482:74592] [SSZipArchive] Error setting directory file modification date attribute: The file “chapter-002-chapter-ii.html” couldn’t be saved in the folder “OEBPS”.
2016-11-04 18:02:28.337 indodragon[9482:74592] [SSZipArchive] Set attributes failed for directory: /Users/crocodic/Library/Developer/CoreSimulator/Devices/C8DC5F44-B2FC-4FC3-8E10-B87FC00791FA/data/Containers/Data/Application/2ABE6535-FE74-4F4D-AC2C-B19C85AD94C0/Documents/EPUB.epub/OEBPS/title-page.html.
2016-11-04 18:02:28.337 indodragon[9482:74592] [SSZipArchive] Error setting directory file modification date attribute: The file “title-page.html” couldn’t be saved in the folder “OEBPS”.
2016-11-04 18:02:28.338 indodragon[9482:74592] [SSZipArchive] Set attributes failed for directory: /Users/crocodic/Library/Developer/CoreSimulator/Devices/C8DC5F44-B2FC-4FC3-8E10-B87FC00791FA/data/Containers/Data/Application/2ABE6535-FE74-4F4D-AC2C-B19C85AD94C0/Documents/EPUB.epub/OEBPS/copyright.html.
2016-11-04 18:02:28.338 indodragon[9482:74592] [SSZipArchive] Error setting directory file modification date attribute: The file “copyright.html” couldn’t be saved in the folder “OEBPS”.
2016-11-04 18:02:28.338 indodragon[9482:74592] [SSZipArchive] Set attributes failed for directory: /Users/crocodic/Library/Developer/CoreSimulator/Devices/C8DC5F44-B2FC-4FC3-8E10-B87FC00791FA/data/Containers/Data/Application/2ABE6535-FE74-4F4D-AC2C-B19C85AD94C0/Documents/EPUB.epub/OEBPS/table-of-contents.html.
2016-11-04 18:02:28.338 indodragon[9482:74592] [SSZipArchive] Error setting directory file modification date attribute: The file “table-of-contents.html” couldn’t be saved in the folder “OEBPS”.
2016-11-04 18:02:28.339 indodragon[9482:74592] [SSZipArchive] Set attributes failed for directory: /Users/crocodic/Library/Developer/CoreSimulator/Devices/C8DC5F44-B2FC-4FC3-8E10-B87FC00791FA/data/Containers/Data/Application/2ABE6535-FE74-4F4D-AC2C-B19C85AD94C0/Documents/EPUB.epub/OEBPS/assets/pressbooks-promo.png.
2016-11-04 18:02:28.339 indodragon[9482:74592] [SSZipArchive] Error setting directory file modification date attribute: The file “pressbooks-promo.png” couldn’t be saved in the folder “assets”.
2016-11-04 18:02:28.339 indodragon[9482:74592] [SSZipArchive] Set attributes failed for directory: /Users/crocodic/Library/Developer/CoreSimulator/Devices/C8DC5F44-B2FC-4FC3-8E10-B87FC00791FA/data/Containers/Data/Application/2ABE6535-FE74-4F4D-AC2C-B19C85AD94C0/Documents/EPUB.epub/OEBPS/assets/MedulaOne-Regular.ttf.
2016-11-04 18:02:28.340 indodragon[9482:74592] [SSZipArchive] Error setting directory file modification date attribute: The file “MedulaOne-Regular.ttf” couldn’t be saved in the folder “assets”.
2016-11-04 18:02:28.340 indodragon[9482:74592] [SSZipArchive] Set attributes failed for directory: /Users/crocodic/Library/Developer/CoreSimulator/Devices/C8DC5F44-B2FC-4FC3-8E10-B87FC00791FA/data/Containers/Data/Application/2ABE6535-FE74-4F4D-AC2C-B19C85AD94C0/Documents/EPUB.epub/OEBPS/pressbooks-promo.html.
2016-11-04 18:02:28.340 indodragon[9482:74592] [SSZipArchive] Error setting directory file modification date attribute: The file “pressbooks-promo.html” couldn’t be saved in the folder “OEBPS”.
2016-11-04 18:02:28.340 indodragon[9482:74592] [SSZipArchive] Set attributes failed for directory: /Users/crocodic/Library/Developer/CoreSimulator/Devices/C8DC5F44-B2FC-4FC3-8E10-B87FC00791FA/data/Containers/Data/Application/2ABE6535-FE74-4F4D-AC2C-B19C85AD94C0/Documents/EPUB.epub/OEBPS/jackson.css.
2016-11-04 18:02:28.341 indodragon[9482:74592] [SSZipArchive] Error setting directory file modification date attribute: The file “jackson.css” couldn’t be saved in the folder “OEBPS”.
2016-11-04 18:02:28.341 indodragon[9482:74592] [SSZipArchive] Set attributes failed for directory: /Users/crocodic/Library/Developer/CoreSimulator/Devices/C8DC5F44-B2FC-4FC3-8E10-B87FC00791FA/data/Containers/Data/Application/2ABE6535-FE74-4F4D-AC2C-B19C85AD94C0/Documents/EPUB.epub/book.opf.
2016-11-04 18:02:28.341 indodragon[9482:74592] [SSZipArchive] Error setting directory file modification date attribute: The file “book.opf” couldn’t be saved in the folder “EPUB.epub”.
2016-11-04 18:02:28.342 indodragon[9482:74592] [SSZipArchive] Set attributes failed for directory: /Users/crocodic/Library/Developer/CoreSimulator/Devices/C8DC5F44-B2FC-4FC3-8E10-B87FC00791FA/data/Containers/Data/Application/2ABE6535-FE74-4F4D-AC2C-B19C85AD94C0/Documents/EPUB.epub/META-INF/container.xml.
2016-11-04 18:02:28.342 indodragon[9482:74592] [SSZipArchive] Error setting directory file modification date attribute: The file “container.xml” couldn’t be saved in the folder “META-INF”.
2016-11-04 18:02:28.342 indodragon[9482:74592] [SSZipArchive] Set attributes failed for directory: /Users/crocodic/Library/Developer/CoreSimulator/Devices/C8DC5F44-B2FC-4FC3-8E10-B87FC00791FA/data/Containers/Data/Application/2ABE6535-FE74-4F4D-AC2C-B19C85AD94C0/Documents/EPUB.epub/META-INF/com.apple.ibooks.display-options.xml.
2016-11-04 18:02:28.343 indodragon[9482:74592] [SSZipArchive] Error setting directory file modification date attribute: The file “com.apple.ibooks.display-options.xml” couldn’t be saved in the folder “META-INF”.
fatal error: unexpectedly found nil while unwrapping an Optional value
我的目标下载代码:
let destination: Alamofire.Request.DownloadFileDestination = { _, _ in
let documentsURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
let fileURL = documentsURL.URLByAppendingPathComponent("\(magazineObject.title).epub")
return fileURL
}
显示epub:
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
let filePath = "\(documentsPath)/\(magazineObject.title).epub"
print(filePath)
FolioReader.presentReader(parentViewController: self, withEpubPath: filePath, andConfig: config, shouldRemoveEpub: false)
答案 0 :(得分:3)
我找到了解决方案。很简单,删除shouldRemoveEpub: false
。所以完整的代码必须是这样的:
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
let filePath = "\(documentsPath)/\(magazineObject.title).epub"
print(filePath)
FolioReader.presentReader(parentViewController: self, withEpubPath: filePath, andConfig: config)