您需要AVCaptureSession和AVCaptureDevice的組合才能從麥克風讀取 - 請參閱AV Foundation編程指南。 http://developer.apple.com/library/ios/#DOCUMENTATION/AVFoundation/Reference/AVCaptureAudioDataOutput_Class/Reference/Reference.html#//apple_ref/occ/cl/AVCaptureAudioDataOutput
對於鏈接使用sokets
@interface Client : NSObject {
NSInputStream *_inputStream;
NSOutputStream *_outputStream;
}
@implementation Client
- (void)initNetworkCommunication {
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"localhost", 50000, &readStream, &writeStream);
_inputStream = (__bridge NSInputStream *)readStream;
_outputStream = (__bridge NSOutputStream *)writeStream;
[_inputStream setDelegate:self];
[_outputStream setDelegate:self];
[_inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[_outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[_inputStream open];
[_outputStream open];
}
// send data to server
- (IBAction)onSendButtonTapped:(id)sender {
NSString *command = self.commandField.text;
NSData *data = [[NSData alloc] initWithData:[command dataUsingEncoding:NSUTF8StringEncoding]];
[_outputStream write:[data bytes] maxLength:[data length]];
}