问题
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