NSData dataWithContentOfFile Rückkehr nil?
Ich habe eine Datei Weg, und ich brauche, um die Daten der Datei in NSData. Ich bin mit:
NSError *err = nil;
NSData *d = [NSData dataWithContentsOfFile:file options:nil error:&err];
NSLog(@"error: %@", err);
Fehler:
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"}
Aber die Datei/das Verzeichnis existiert, weil ich mich spielen die video-Datei und es funktioniert Prima:
MPMoviePlayerViewController *controller = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[video filepath]]];
[self presentMoviePlayerViewControllerAnimated:controller];
Was mache ich falsch?
Dank
Du musst angemeldet sein, um einen Kommentar abzugeben.
Übergeben Sie eine URL im format-string zu dataWithContentsOfFile, müssen Sie die "Datei-Pfad" für die Datei.
In diesem Fall müssen Sie entfernen "file://localhost" aus dem string. Wenn die Datei existiert, das sollte funktionieren.
NSString *path = [[NSURL URLWithString:file] path];
um die Datei zu konvertieren URL, um einen unix-Pfad.