0

アプリのDocumentsディレクトリを使用して画像を保存し、後でhtmlを含むWebビューでアクセスしようとしています。/ var / mobile / Applications / id / Documentsを使用してみましたが、機能しませんでした。Webビューでこれらのファイルにアクセスする方法はありますか?

4

2 に答える 2

0

/を見逃したことが判明したので、file:/// var / mobile / Applications / id / Documentsである必要があり、それで機能しました。

于 2012-11-04T00:00:09.743 に答える
0

画像を保存するには、キャッシュディレクトリにNSMutableDataのような画像をダウンロードする必要があります。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDirectory = [paths objectAtIndex:0];
NSString* filePath = [NSString stringWithFormat:@"%@/imageTemp.png",cachesDirectory];
[imageData writeToFile:filePath atomically:YES];

ダウンロード後、画像をドキュメントディレクトリに移動できます。

NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *arrayPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [arrayPath objectAtIndex:0];
NSString *cacheImagePath = filePath;
NSError *error;
[fileManager copyItemAtPath:cacheImagePath toPath:documentPath error:&error];
于 2012-10-30T23:39:47.413 に答える