2014-05-01 60 views
0

您好我正在創建一個演示應用程序來記錄音頻。我按照這個教程從文檔到服務器發佈音頻文件

Link to tutorial

// Set the audio file 
    NSArray *pathComponents = [NSArray arrayWithObjects: 
           [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject], 
           @"MyAudioMemo.m4a", 
           nil]; 
    NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents]; 

    // Setup audio session 
    AVAudioSession *session = [AVAudioSession sharedInstance]; 
    [session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil]; 

    // Define the recorder setting 
    NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init]; 

    [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey]; 
    [recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
    [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey]; 

    // Initiate and prepare the recorder 
    recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:NULL]; 
    recorder.delegate = self; 
    recorder.meteringEnabled = YES; 
    [recorder prepareToRecord]; 

錄音部分工作正常並且應用程序正在播放的音頻文件,

問題: 我如何上傳錄製的文件到服務器。

+1

有你實現web服務? –

+0

您可以使用ASIHttpRequest或任何其他框架將outputFilePath上傳到服務器。請參閱http://allseeing-i.com/ASIHTTPRequest/ – Natarajan

+0

如果問題是「如何上傳文件?」爲什麼要寫所有這些員工?請關閉此票並打開更具體的票。 – Avt

回答

0

你可以用以下的例子:

NSURLSession *session = [NSURLSession sharedSession]; 
[[session uploadTaskWithRequest:[NSURLRequest requestWithURL:your_url] 
         fromFile:file_url 
      completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 

      }] resume]; 

請在這裏閱讀更多http://www.raywenderlich.com/51127/nsurlsession-tutorial

+0

感謝回答真的很感謝 – ozi

+0

不客氣。如果你需要更多的可能性,你也可以看看AFNetworking庫。 https://github.com/AFNetworking/AFNetworking – Avt

相關問題