user2353899
user2353899

Reputation:

The operation couldn’t be completed. (Cocoa error 260.)

I'm new on IOS development and i'm working on a pdf application and i need to store a PDF file on a NSData variable, I have the PDF path but i get this message error when i try to put this pdf on the NSData variable using dataWithContentsOfFile her is my simple code :

NSError *error;
NSString *PdfPath = [NSString stringWithFormat:(@"%@"),document.fileURL ];
NSString *newPath = [PdfPath stringByReplacingOccurrencesOfString:@"file://localhost" withString:@""];
NSLog(@"OriginalPdfPath => %@", newPath);
NSData *pdfData = [NSData dataWithContentsOfFile:newPath options:NSDataReadingUncached error:&error];

NB : the pdf path is in this format : /Users/bluesettle/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/BBEF320E-7E2A-49DA-9FCF-9CFB01CC0402/ContractApp.app/Pro.iOS.Table.Views.pdf

thanks for your help

Upvotes: 2

Views: 16430

Answers (2)

Andreas Ley
Andreas Ley

Reputation: 9355

Cocoa error 260 is a NSFileReadNoSuchFileError (as listed in FoundationErrors.h), meaning the file could not be found at the path you specified.

The problem is that your path still contains encoded spaces (%20), because you're basing it on the URL. You can simply do this:

NSData *pdfData = [NSData dataWithContentsOfFile:[document.fileURL path]];

Upvotes: 8

B.S.
B.S.

Reputation: 21726

Try to use NSBundle

NSString *newPath = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"pdf"]

Edit:

Than you can use bundleWithPath method, here is an example:

NSString *documentsDir= [NSString stringWithFormat:@"%@/Documents", NSHomeDirectory()];

NSString *newPath= [[NSBundle bundleWithPath:documentsDir] bundlePath];

Upvotes: 1

Related Questions