0

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

Brian Postow
  • 11,709
  • 17
  • 81
  • 125

3 Answers3

3

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

Mike Abdullah
  • 14,933
  • 2
  • 50
  • 75
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);
Ted Person
  • 21
  • 2
0

Error code -15 is is kCFURLImproperArgumentsError.

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

JOM
  • 8,139
  • 6
  • 78
  • 111