2010-04-28 2 views
0

이 코드는 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 { 

    } 
} 

답변

0

루프에서 모두 수행 중이므로 자동 복구 풀이 가득 찼을 가능성이 큽니다. 수동 오토 릴리즈 풀을 세척하거나 수동으로 메모리 해제 :

NSData data = [[NSData alloc] initWithContentsOfFile:component]; 
[data writeToFile:writableAudioPath atomically:NO]; 
[data release]; 
+0

답장을 보내 주셔서 감사합니다. 나는 당신과 동의하고 autorelease 풀을 구현했습니다. 결과는 불행히도 동일했습니다. 그런 다음 NSData writeToFile에 대한 NSFileManager copyItemAtPath를 바꿨습니다. 여전히 결과는 같습니다. 로드하는 동안 앱이 다운됩니다. – user273565

0
NSFileManager *fileManager = [[NSFileManager alloc] init]; 

어둠 속에서 자상을,하지만 당신은 NSFileManager를의 스레드 안전 버전 사용하여 시도가 :

NSFileManager* filemanager = [NSFileManager defaultManager]; 
1

을 OS가 특정 시간 내에 실행되지 않으면 앱이 종료됩니다. 백그라운드 스레드에서 복사본을 만들어보십시오.

0

당신은 아마 iOS 워치 독에 의해 사망하고 있습니다. 실행하는 데 너무 오래 걸리는 앱은 종료됩니다. didFinishLaunching 메서드를 종료 한 후에 실행되도록 performSelector:withObject:afterDelay: 메서드를 호출 해보십시오.

관련 문제