2011-01-07 2 views
0

사용자가 버튼을 클릭하여 문서 디렉토리에 벨소리를 저장할 수있는 앱이 있습니다. 내가 iPad 버전을 제대로 작동하지만, 아이폰에 대한 동일한 방법을 사용하여 작동하지 않는 것 같습니다. 저장하기 위해 사용하는 코드는 다음과 같습니다.파일 공유로 파일을 저장하는 iPhone 문제

- (IBAction) saveFile:(id)sender { 
    // Get the path to the Documents Directory 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 

    // Detect which button was double tapped and set up the file to save 
    NSString *filePath; 
    NSString *fileName; 
    if (sender == downloadRingtone1){ 
      filePath = [[NSBundle mainBundle] pathForResource:@"RingtoneTest" ofType:@"m4r"]; 
      fileName = @"RingtoneTest.m4r"; 
    } else if (sender == downloadRingtone2){ 
      filePath = [[NSBundle mainBundle] pathForResource:@"RingtoneTest2" ofType:@"m4r"]; 
      fileName = @"RingtoneTest2.m4r"; 

    NSString *m4rPath = [documentsDirectory stringByAppendingPathComponent:fileName]; 
    NSFileManager *fileManager = [NSFileManager defaultManager]; 

    // Detect if the file already exists 
    BOOL fileExists = [fileManager fileExistsAtPath:m4rPath]; 

    if (fileExists) { 
      UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"File Already Saved" message:@"The selected file already exists. Sync to iTunes to finish loading the file." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease]; 
      [alert show]; 
    } else {   
      // Save the file   
      [fileManager copyItemAtPath:filePath toPath:m4rPath error:nil]; 

      // Notify of the save 
      UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"File Saved" message:@"You must sync your device to iTunes to finish loading. For complete instructions, visit the \"Download Instructions\" page." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease]; 
      [alert show]; 
    } 
} 

파일 관리자에 문제가 있습니다. 게시됨에 따라 파일이있는 것처럼 항상 if 문으로 이동합니다 (그렇지 않은 경우). if 문을 저장하여 강제로 주석 처리하면 앱이 다운됩니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? iPhone과 다른 점이 있습니까? 또한 문제는 아니지만 iPod touch에서 테스트 중입니다 (최신 IOS 4.2.1로 업데이트 됨). iPhone에 대한 액세스 권한이 없습니다.

답변

0

위 코드가 정확합니다. 동일한 문제가있는 경우 인터페이스 빌더의 버튼을 올바른 콘센트에 연결해야합니다.

관련 문제