iPhone使用文件共享保存文件时出现问题

iPhone使用文件共享保存文件时出现问题,iphone,nsfilemanager,file-sharing,ringtone,Iphone,Nsfilemanager,File Sharing,Ringtone,我有一个应用程序,允许用户单击按钮将铃声保存到documents目录。我的iPad版本工作正常,但是,在iPhone上使用相同的方法似乎不起作用。下面是我用来保存的代码: - (IBAction) saveFile:(id)sender { // Get the path to the Documents Directory NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUs

我有一个应用程序,允许用户单击按钮将铃声保存到documents目录。我的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。请提供任何帮助。

上述代码是正确的。如果有人遇到同样的问题,请确保将按钮连接到Interface Builder中的正确插座