0

我试图从消息扩展的 SKDownload 中获取内容,然后总是得到权限错误。(xCode 8 b4、iPhone 5、iOS 10 b4) 在此处输入图像描述

在此处输入图像描述

class func image(from url: URL?) -> UIImage? {

    print(url?.path)


    let fileManager = FileManager.default

    print(fileManager.fileExists(atPath: url!.path))


    guard let url = url, fileManager.fileExists(atPath: url.path) else {
        return nil
    }

    do {
       let attributes: [FileAttributeKey : AnyObject] = try fileManager.attributesOfItem(atPath: url.path)
       print(attributes)

    } catch {
        print(error)
    }

    let content = fileManager.subpaths(atPath: (url.path) )
    print(content)

    let contents = fileManager.contents(atPath: (url.path) )
    print(contents)

    do {
        let contentsOfDirectory = try fileManager.contentsOfDirectory(atPath: url.path)
        print("contentsOfDirectory \(contentsOfDirectory)")

    } catch {
        print("contentsOfDirectory \(error)")
    }

    do {
        let contentsOfDirectory = try fileManager.subpathsOfDirectory(atPath: url.path)
        print("subpathsOfDirectory \(contentsOfDirectory)")

    } catch {
        print("subpathsOfDirectory \(error)")
    }

    let coordinator = NSFileCoordinator()

    coordinator.coordinate(readingItemAt: url, options: NSFileCoordinator.ReadingOptions(rawValue: 0), error: nil, byAccessor: {(newUrl) in
        do {
            let contentsOfDirectory = try fileManager.contentsOfDirectory(atPath: newUrl.path)
            print("newUrl contentsOfDirectory \(contentsOfDirectory)")

        } catch {
            print("newUrl contentsOfDirectory \(error)")
        }
        print(newUrl)
    })
    let dirEnum = fileManager.enumerator(atPath: url.path)
    while let filename = dirEnum?.nextObject() {
        print("file name \(filename)")
    }

    let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
    let destPath = paths[0] + "\(Date().timeIntervalSince1970)"
    do {
        try fileManager.copyItem(atPath: url.path, toPath: destPath)
    } catch {
        print("copy error = \(error)")
    }

    return nil
}
4

0 回答 0