CFURLCopyResourcePropertyForKey failed because passed URL no scheme
For me this problem was fixed by adding
file://
right before the file path address like this:
var filePath = "file://\(fileURLpath)"
Or maybe you can use NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("mypictostore", ofType: "png")!)
instead of using NSURL(string: NSBundle.mainBundle().pathForResource("mypictostore", ofType: "png")!)
Look this link for Objective-c answer: CFURLSetResourcePropertyForKey failed when disable data backup on NSDocumentDirectory
Older Swift version answer:
var str:String = "/var/mobile/Containers/Data/Application/3039975A-5E05-4A4C-8000-55C681A7C35F/Documents/index.html"
var url:URL = URL.init(fileURLWithPath: str)
Swift 4 Answer:
var str:String = "/var/mobile/Containers/Data/Application/3039975A-5E05-4A4C-8000-55C681A7C35F/Documents/index.html"
var url:URL = URL(string: str)!
look, I find this,The url
is The location to write the data into
. we should tell the system a file path
.
- var filePath = "file://(fileURLpath)"
- var url:URL = URL.init(fileURLWithPath: fileURLpath)
Data