iPhone - NSData from local file's URL
Solution 1:
// Given some file path URL: NSURL *pathURL
// Note: [pathURL isFileURL] must return YES
NSString *path = [pathURL path];
NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];
Swift code:
let data = FileManager.default.contents(atPath: path)
Solution 2:
To get this work you just need to do:
NSURL *imgPath = [[NSBundle mainBundle] URLForResource:@"search" withExtension:@"png"];
NSString*stringPath = [imgPath absoluteString]; //this is correct
//you can again use it in NSURL eg if you have async loading images and your mechanism
//uses only url like mine (but sometimes i need local files to load)
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:stringPath]];
UIImage *ready = [[[UIImage alloc] initWithData:data] autorelease];
Solution 3:
Make sure your local URL starts with "file://" then you would just have to do this:
NSData *fileData = [NSData dataWithContentsOfFile:fileURL.path];