iPhone 장치에서 NSFileManager로 디렉토리 및 파일을 만드는 데 문제가 있습니다. 아래에 표시된 내 코드는 시뮬레이터에서 제대로 작동하지만 기기에서는 작동하지 않습니다. 제발 도와주세요. 이리 문제가 될 수있는 몇 가지 방향으로, 모든 답장을 보내 주셔서 감사합니다 ..NSFileManager는 시뮬레이터에서 정상적으로 작동하지만 장치에서는 작동하지 않습니다.
은 내가 먼저 디렉토리 이런 식으로 만드는거야 :
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSArray *arPaths = NSSearchPathForDirectoriesInDomains(NSDownloadsDirectory, NSUserDomainMask, YES);
NSString *appPath = [[NSString alloc] init];
appPath = [arPaths objectAtIndex:0];
strDownloadsDir = [[NSString alloc] init];
strDownloadsDir = [[appPath stringByAppendingPathComponent:@"/Other"] copy];
if(![fileMgr fileExistsAtPath:strDownloadsDir])
[fileMgr createDirectoryAtPath:strDownloadsDir attributes:nil];
을 한 후 나는이 디렉토리에이 방법을 새 파일을 만들려고 해요 :
NSString *filePath = [strDownloadsDir stringByAppendingPathComponent:strDlFileName];
//Test whether this file exists, if not, create it
NSLog(@"%@", filePath);
if(![fileMgr fileExistsAtPath:filePath])
{
if([fileMgr createFileAtPath:filePath contents:nil attributes:nil])
NSLog(@"Creating new file at path %@", filePath);
else
NSLog(@"Failed to create new file.");
}
은 전체 NSFileManager를에 문제가 있음을 보인다, 나는이
NSArray *arPaths = NSSearchPathForDirectoriesInDomains(NSDownloadsDirectory, NSUserDomainMask, YES);
NSString *appPath = [[NSString alloc] init];
appPath = [arPaths objectAtIndex:0];
에 의해 주어진 경로로 fileExistAtPath을 사용하고 때 때문에 6,
는 너무 작동하지 않습니다, 나는 NSDocumentsDirectory로 디렉토리를 변경하려고하지만 방법을 사용하기 때문에
많은 NSString이 누출됩니다. 불필요한'[[NSString alloc] init];'을하지 마십시오. – kennytm