Swift - 打开导入app的文件

时间:2017-06-08 16:17:02

标签: ios swift xcode file uti

您好我有一个使用自己的文档格式(.hvgg)的应用程序。 UTI在Info.plist中声明(屏幕截图)。我做错了吗?因为当我使用“共享”菜单时,它显示“复制到HvGG”而不是“导入到HvGG”,它与所有其他应用程序一起显示。

Screenshot #1

无论如何,我的实际问题是我找不到导入的文件。我试图使用文档目录找到它并添加“收件箱”,但这不起作用。是否有保存文件的新路径?

这是我的代码:

var opened: String?
var path: String?

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

    if String(describing: url)[0..<4] == "file" {
        opened = "stundenplan"
        let filemanager = FileManager.default
        let paths: NSArray = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) as NSArray
        let documentsDirectory: String = paths.object(at: 0) as! String
        path = documentsDirectory.appending("/Inbox")
        let dirFiles = try! filemanager.contentsOfDirectory(atPath: path!) <-- throws error

        print (dirFiles) 


    }

    return true
}

它返回的错误:

fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=260 "The folder “Inbox” doesn’t exist." UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/9C0586AF-C0B8-440A-9151-13C6A061B3FB/Documents/Inbox, NSUserStringVariant=(
Folder), NSUnderlyingError=0x174050e90 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-802.0.31.3/src/swift/stdlib/public/core/ErrorType.swift, line 182

0 个答案:

没有答案