NSData dataWithContentOfFile returns nil?

I have a file path and I need to get the file data into NSData. I use:

NSError *err = nil;
NSData *d = [NSData dataWithContentsOfFile:file options:nil error:&err];

NSLog(@"error: %@", err);

      

Mistake:

 Error Domain=NSCocoaErrorDomain Code=260 "The operation couldn’t be completed. (Cocoa error 260.)" UserInfo=0x34a8f0 {NSFilePath=file://localhost/var/mobile/Applications/A19223D4-0AEF-4677-8EDD-0D2CA9A7BB73/Documents/12-03-25%2022:10:48--cc.mp4, NSUnderlyingError=0x34a560 "The operation couldn’t be completed. No such file or directory"}

      

But the file / directory exists because I am playing a video file and it works fine:

MPMoviePlayerViewController *controller = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[video filepath]]];
[self presentMoviePlayerViewControllerAnimated:controller];

      

What's going wrong? Thanks to

+3


source to share


1 answer


You are passing the url in string format dataWithContentsOfFile, you have to use "file path" for the file.



In this case, you need to remove "file: // localhost" from the line. If the file exists, this should work.

+6


source







All Articles