バイナリ ファイルをダウンロードして、「Documents」フォルダにカスタム名で完全に保存できます。
URL を「Documents」フォルダではなく「Application Support」フォルダに変更しただけでは、その URL が存在しないと言って書き込みに失敗します。
URL 構築コードは次のとおりです。
- ( NSURL * ) getSaveFolder
{
NSURL * appSupportDir = nil;
NSURL * appDirectory = nil;
NSArray * possibleURLs = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSAllDomainsMask];
if ( [possibleURLs count] >= 1 )
{
appSupportDir = [possibleURLs objectAtIndex:0];
}
if ( appSupportDir != nil)
{
NSString * appBundleID = [[NSBundle mainBundle] bundleIdentifier];
appDirectory = [appSupportDir URLByAppendingPathComponent:appBundleID];
}
return appSupportDir;
}
保存コードは次のとおりです。
- ( void ) writeOutDataToFile:( NSData * )data
{
NSURL * finalURL = [self.rootPathURL URLByAppendingPathComponent:self.aFileName];
[data writeToURL:finalURL atomically:YES];
}
NSArray を次のように変更すると:
NSArray * possibleURLs = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];
その後、正常に保存されます。
ファイル関連の Apple Docs を読みましたが、これを修正できません。何が足りないのでしょうか?