Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CFURLCopyResourcePropertyForKey failed because passed URL no scheme

I have a program that saves a file to the iCloud and this has worked great for iOS7, but now I get this error with iOS8 and cannot seem to find the answer on how to fix it. Anyone else had this problem? Any ideas would be greatly appreciated.

The Error: CFURLCopyResourcePropertyForKey failed because it was passed this URL which has no scheme: /var/mobile/Containers/Data/Application/ASFHDDE3-B1BB-41D7-A47C-DCC328362W21/Documents/mypictostore.png

The Line of Code Throws Error: [fileManager setUbiquitous:YES itemAtURL:backupUrl destinationURL:[[ubiq URLByAppendingPathComponent:@"Documents" isDirectory:true] URLByAppendingPathComponent:backupName] error:&theError];

URLS: destinationURL: file:///private/var/mobile/Library/Mobile%20Documents/ABC23455~MY-Program/ backupUrl: /var/mobile/Containers/Data/Application/ASDFGEEW-B1BB—6FR6-A47C-DCCF21876D36/Documents/mypic.png

Thank you, Jon

like image 375
Jon Avatar asked Sep 27 '14 23:09

Jon


4 Answers

For me this problem was fixed by adding

file://

right before the file path address like this:

var filePath = "file://\(fileURLpath)"
like image 131
Jorge Irún Avatar answered Nov 03 '22 23:11

Jorge Irún


Or maybe you can use NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("mypictostore", ofType: "png")!) instead of using NSURL(string: NSBundle.mainBundle().pathForResource("mypictostore", ofType: "png")!)

like image 22
leonard Avatar answered Nov 04 '22 01:11

leonard


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)!
like image 15
Renato Ioshida Avatar answered Nov 03 '22 23:11

Renato Ioshida


Depending on what you need to do with the path, you may need to prepend the scheme file://. See more at documentation/foundation/url

If you need the file path, use fileURLWithPath:

let imageURL = URL(fileURLWithPath: imagePath)

it will give you the path as

file:///var/mobile/Containers/Data/Application/7C1D854B-8A2E-4FF0-BD30-0652AEE10B6F/Documents/image_8ZMAM.jpg


If you need the path without the scheme, use string:

let imageURL = URL(string: imagePath)

it will give you the path as

/var/mobile/Containers/Data/Application/7C1D854B-8A2E-4FF0-BD30-0652AEE10B6F/Documents/image_8ZMAM.jpg

like image 8
micaball Avatar answered Nov 03 '22 23:11

micaball