如何加密/隐藏文档目录中的下载文件,以便swift 3 *中的设备中的用户不可见文件

时间:2017-12-27 12:14:21

标签: xcode swift4 nsdocumentdirectory

代码:

let url = NSURL(string: urlString)
            let urlData1 = NSData(contentsOf: url! as URL)
            if(urlData1 != nil)
            {
                let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0];
                let fileManager = FileManager.default
                if let tDocumentDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first {
                    let filePathURL =  tDocumentDirectory.appendingPathComponent("eMedicoz")
                    if !fileManager.fileExists(atPath: filePathURL.path) {
                        do {
                            try fileManager.createDirectory(atPath: filePathURL.path, withIntermediateDirectories: true, attributes: nil)
                        } catch {
                            NSLog("Couldn't create document directory")
                        }
                    }
                NSLog("Document directory is \(filePathURL)")

                let filePath="\(filePathURL.path)" + "/" + fileName

             DispatchQueue.main.async {
                urlData?.write(toFile: filePath, atomically: true);
                    PHPhotoLibrary.shared().performChanges({
                        PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: NSURL(fileURLWithPath: filePath) as URL)
                    }) { completed, error in
                        if completed {
                            print("Video is saved!")
                            completionHandler(true,"Video Save",nil)
                        }
                        else{
                            completionHandler(false,"error",error! as NSError)
                        }
                    }
        }

如何加密/隐藏文档目录中的下载文件,以便swift 3 *中的设备中的用户看不到该文件    提前谢谢。

0 个答案:

没有答案