3
私はファイルパスを持っており、NSDataのファイルのデータを取得する必要があります。私が使用しています:NSData dataWithContentOfFileはnilを返しますか?
NSError *err = nil;
NSData *d = [NSData dataWithContentsOfFile:file options:nil error:&err];
NSLog(@"error: %@", err);
エラーは次のとおりです。
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"}
しかし、私はビデオファイルを再生していますので、ファイル/ディレクトリが存在しないとそれだけで正常に動作します:
MPMoviePlayerViewController *controller = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[video filepath]]];
[self presentMoviePlayerViewControllerAnimated:controller];
は何ですか間違っている? ありがとう
file:// localhostを削除できるNSStringの便利なメソッドはありますか? – 0xSina
"file:// localhost"という接頭辞を単に削除しないでください。ファイルのURLをunixパスに変換するには、 'NSString * path = [[NSURL URLWithString:file] path];'を使います。 –
はい、NSURLクラスには[url path]があります。しかし、あなたは文字列としてURLを持っているので、最初にURLを作成する必要があります。NSURL * url = [NSURL URLWithString:yourURLString] – LuisEspinoza