이 코드는 applicationDidFinishLaunching에서 호출 한 메서드에 있습니다. 시뮬레이터에서는 작동하지만 iPhone에서는 작동이 중단됩니다. 이 작업에는 약 1,600 개의 2KB mp3 파일이 복사됩니다. 앱을 여러 번 인스턴스화하려고하면 결국 앱이 충돌없이 시작될 때까지 매번 더 많은 시간이 복사됩니다. 내가 할당 한 모든 것을 공개합니다. iPhone에는 약 20GB의 디스크 공간이 있습니다. 점진적으로 코드를 주석 처리하고 iPhone에서 실행하면 copyItemAtPath가 용의자 인 것 같습니다.NSFileManager 응용 프로그램 대리자에서 충돌 발생
- (void)createCopyOfAudioFiles:(BOOL)force {
@try {
NSError *error;
NSString *component;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSEnumerator *enumerator = [[[NSBundle mainBundle]pathsForResourcesOfType:@"mp3" inDirectory:nil] objectEnumerator];
while ((component = [enumerator nextObject]) != nil) {
NSArray *temp = [component componentsSeparatedByString:@".app/"];
NSString *file = [NSString stringWithFormat:@"%@", [temp objectAtIndex:1]];
NSString *writableAudioPath = [documentsDirectory stringByAppendingPathComponent:file];
BOOL success = [fileManager fileExistsAtPath:writableAudioPath];
if (success && !force) {
continue;
} else if (success && force) {
success = [fileManager removeItemAtPath:writableAudioPath error:&error];
}
success = [fileManager copyItemAtPath:component toPath:writableAudioPath error:&error];
if (!success) {
@throw [NSException exceptionWithName:[error localizedDescription] reason:[error localizedFailureReason] userInfo:nil];
}
}
[fileManager release];
}
@catch (NSException *exception) {
NSLog(@"%@", exception);
@throw [NSException exceptionWithName:exception.name reason:exception.reason userInfo:nil];
}
@finally {
}
}
답장을 보내 주셔서 감사합니다. 나는 당신과 동의하고 autorelease 풀을 구현했습니다. 결과는 불행히도 동일했습니다. 그런 다음 NSData writeToFile에 대한 NSFileManager copyItemAtPath를 바꿨습니다. 여전히 결과는 같습니다. 로드하는 동안 앱이 다운됩니다. – user273565