JSONファイルを使用してpdfファイルをダウンロードするiPhoneアプリケーションがあり、JSON応答は次のようになります
{
"resource_id":"1132",
"name_en":"mpla mpla mpla",
"name_cn":null,
"product_id":"1064",
"product":"mpla",
"category":"mpla Literature",
"fileURLString_en":"http://mpla.mpla.com/media/427/mpla.pdf",
"fileURLString_en_date":"Mon, 03 Sep 2012 08:53:40 GMT",
"fileURLString_cn":"http://mpla.mpla.com/media/427/mpla.pdf",
"fileURLString_cn_date":"Mon, 03 Sep 2012 08:53:40 GMT",
"thumbnailURLString_en":"http://mpla.mpla.com/media/1472/mpla.png",
"emailURLString_en":null,
"emailURLString_en_date":null,
"descriptionString_en":null,
"emailThumbnailURLString_en":null,
"emailThumbnailURLString_en_date":null,
"externalUrl":null
},
Library/Caches/en フォルダに en ファイルをダウンロードし、Library/Cashes/ch フォルダに中国語ファイルをダウンロードします。
私は通信部分に ASIHTTPRequest を使用しています! 特定のフォルダにファイルをダウンロードして保存するための(コードでの)提案は何ですか?
これまでの私のコードは次のとおりです。
-(void)createDirectory:(NSString *)directoryName atFilePath:(NSString *)filePath
{
NSString *filePathAndDirectory = [filePath stringByAppendingPathComponent:directoryName];
NSLog(@"%@",filePathAndDirectory);
NSError *error;
if (![[NSFileManager defaultManager] createDirectoryAtPath:filePathAndDirectory withIntermediateDirectories:NO
attributes:nil
error:&error])
{
NSLog(@"Create directory error: %@", error);
}
}
NSString* filePath=[NSString stringWithFormat:@""];
NSString *clanguage = [[NSLocale preferredLanguages] objectAtIndex:0];
if([clanguage isEqualToString:@"en"])
{
NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
filePath = [NSString stringWithFormat:@"%@/en/%@",cachesPath,urlPath.lastObject];
}
else if([clanguage isEqualToString:@"zh-Hans"])
{
NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
filePath = [NSString stringWithFormat:@"%@/cn/%@",cachesPath,urlPath.lastObject];
}
2 つのサブフォルダーを作成しようとしましたが、リンクによってはファイルを保存できません。また、ファイルの名前を英語の名前に変更し、中国語の ch_name に変更しようとしましたが、それは便利ではありません!