CFURLCreateDataAndPropertiesFromResource failed with error code -15

心不动则不痛 提交于 2019-12-25 03:16:52

问题


I'm trying to lead a TIFF image into a CGImageSource using CGImageSourceCreateWithURL. My URL is correct, is %20 encoded, is a path to an existing file, that file is a TIFF. However, the line:

NSString *fullPath =  [[[fileNames objectAtIndex:pageNum - 1] string]
                          stringByAddingPercentEscapesUsingEncoding: 
                              NSUTF8StringEncoding];
NSString* urlStr = [NSString stringWithFormat: @"file:/%@", fullPath];
NSURL * url = [NSURL URLWithString: fullPath];

CGImageSourceRef src = CGImageSourceCreateWithURL (url, NULL);

gives me the following error:

Wed Aug  4 20:17:20 Brians-mini.local DocKeep[17199] <Error>: CGImageSourceCreateWithURL:  CFURLCreateDataAndPropertiesFromResource failed with error code -15.

anyone know what error -15 is? or where I can find it?

thanks

ETA: I should also mention that I don't have this problem if the path doesn't have spaces in it... (Spaces in filenames are an abomination unto the lord, but I suppose we have to live with them... B-)


回答1:


Don't use +URLWithString: for this. Instead use the purpose-built +fileURLWithPath:




回答2:


Try this:

NSString *fullPath =  [[fileNames objectAtIndex:pageNum - 1] string];
CFStringRef fullPathEscaped = CFURLCreateStringByAddingPercentEscapes(NULL, 
            (CFStringRef)pdfPath, NULL, NULL,kCFStringEncodingUTF8);

CFURLRef url = CFURLCreateWithString(NULL, fullPathEscaped, NULL);
CGImageSourceRef src = CGImageSourceCreateWithURL (url, NULL);



回答3:


Error code -15 is is kCFURLImproperArgumentsError.

More info at Apple documentation for Core Foundation URL Access Utilities Reference.



来源:https://stackoverflow.com/questions/3410887/cfurlcreatedataandpropertiesfromresource-failed-with-error-code-15

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!