swift - FolioReaderKit fatal error : unexpectedly found nil while unwrapping an optional value

标签 swift epub

我有收藏 View ,用户可以下载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)

最佳答案

我找到了解决方案。很简单,删除 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)

关于swift - FolioReaderKit fatal error : unexpectedly found nil while unwrapping an optional value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40421349/

相关文章:

ios - 使用 Segue 将数据传递给不同的 View Controller

mocking - 在 XCTest 中快速模拟对象的最佳方法是什么?

ios - swift Firebase 删除观察者

ios - Swift 3 - 从共享扩展到主应用程序共享 URL 和标题?

local-storage - iBooks 是否支持 ePUB 格式的 localStorage?

ios - 检测描边 uibezierpath 包含点

javascript - 找出何时通过 Javascript 在 EPUB FXL 中查看页面

java - epub 文件不可下载 [ANDROID]

epub - 我想编写一个脚本将我的 .mobi 文件转换为 epub

javascript - 设置 epub.js