CFURLCopyResourcePropertyForKey failed because passed URL no scheme

Objective CIos8Xcode6

Objective C Problem Overview


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

Objective C Solutions


Solution 1 - Objective C

For me this problem was fixed by adding

file://

right before the file path address like this:

var filePath = "file://\(fileURLpath)"

Solution 2 - Objective C

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

Solution 3 - Objective C

Look this link for Objective-c answer: https://stackoverflow.com/questions/12928509/cfurlsetresourcepropertyforkey-failed-when-disable-data-backup-on-nsdocumentdire

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)!

Solution 4 - Objective C

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

Solution 5 - Objective C

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

Solution 6 - Objective C

You can also try this, I think the following code is great as if you are not sure any particular url is correct or not for the CFURLCopyResourcePropertyForKey

if testURL.isFileURL == false {

    testURL = URL(fileURLWithPath: testURL.absoluteString)

}

Solution 7 - Objective C

var url = USL(fileUrlWithString: "/private/var/...")

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJonView Question on Stackoverflow
Solution 1 - Objective CJorge IrúnView Answer on Stackoverflow
Solution 2 - Objective CleonardView Answer on Stackoverflow
Solution 3 - Objective CRenato IoshidaView Answer on Stackoverflow
Solution 4 - Objective ChuangqibiaoView Answer on Stackoverflow
Solution 5 - Objective CmicaballView Answer on Stackoverflow
Solution 6 - Objective CiNoobView Answer on Stackoverflow
Solution 7 - Objective CzavidovychView Answer on Stackoverflow