From e2ffaafc7040ce26f12d5cc7c3431e88afbfaf7e Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Fri, 16 Apr 2010 11:53:49 +0200 Subject: [PATCH] check the device has a microphone, and if not display an alert. --- Classes/linphoneAppDelegate.m | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/Classes/linphoneAppDelegate.m b/Classes/linphoneAppDelegate.m index c6813d898..a43ff5b37 100644 --- a/Classes/linphoneAppDelegate.m +++ b/Classes/linphoneAppDelegate.m @@ -166,7 +166,7 @@ LinphoneCoreVTable linphonec_vtable = { } - (void)applicationDidBecomeActive:(UIApplication *)application { if (isStarted) { - ms_message(@"becomming active, make sure we are registered"); + ms_message("becomming active, make sure we are registered"); [self doRegister]; } else { isStarted=true; @@ -194,7 +194,19 @@ LinphoneCoreVTable linphonec_vtable = { //init audio session NSError *setError = nil; - [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord error: &setError]; //must be call before linphone_core_init + AVAudioSession *audioSession = [AVAudioSession sharedInstance]; + BOOL bAudioInputAvailable= [audioSession inputIsAvailable]; + + if(!bAudioInputAvailable){ + UIAlertView* error = [[UIAlertView alloc] initWithTitle:@"No microphone" + message:@"You need to plug a microphone to your device to use this application." + delegate:self + cancelButtonTitle:@"Ok" + otherButtonTitles:nil ,nil]; + [error show]; + }else{ + [audioSession setCategory: AVAudioSessionCategoryPlayAndRecord error: &setError]; //must be call before linphone_core_init + } //get default config from bundle NSBundle* myBundle = [NSBundle mainBundle]; @@ -311,42 +323,42 @@ LinphoneCoreVTable linphonec_vtable = { //read from setting bundle if ([[NSUserDefaults standardUserDefaults] boolForKey:@"speex_32k_preference"]) { if(pt = [self findPayload:@"speex"withRate:32000 from:audioCodecs]) { - payload_type_set_enable(pt,TRUE); + linphone_core_enable_payload_type(myLinphoneCore,pt, TRUE); } } if ([[NSUserDefaults standardUserDefaults] boolForKey:@"speex_16k_preference"]) { if(pt = [self findPayload:@"speex"withRate:16000 from:audioCodecs]) { - payload_type_set_enable(pt,TRUE); + linphone_core_enable_payload_type(myLinphoneCore,pt, TRUE); } } if ([[NSUserDefaults standardUserDefaults] boolForKey:@"speex_8k_preference"]) { if(pt = [self findPayload:@"speex"withRate:8000 from:audioCodecs]) { - payload_type_set_enable(pt,TRUE); + linphone_core_enable_payload_type(myLinphoneCore,pt, TRUE); } } if ([[NSUserDefaults standardUserDefaults] boolForKey:@"gsm_22k_preference"]) { if(pt = [self findPayload:@"GSM"withRate:22050 from:audioCodecs]) { - payload_type_set_enable(pt,TRUE); + linphone_core_enable_payload_type(myLinphoneCore,pt, TRUE); } } if ([[NSUserDefaults standardUserDefaults] boolForKey:@"gsm_11k_preference"]) { if(pt = [self findPayload:@"GSM"withRate:11025 from:audioCodecs]) { - payload_type_set_enable(pt,TRUE); + linphone_core_enable_payload_type(myLinphoneCore,pt, TRUE); } } if ([[NSUserDefaults standardUserDefaults] boolForKey:@"gsm_8k_preference"]) { if(pt = [self findPayload:@"GSM"withRate:8000 from:audioCodecs]) { - payload_type_set_enable(pt,TRUE); + linphone_core_enable_payload_type(myLinphoneCore,pt, TRUE); } } if ([[NSUserDefaults standardUserDefaults] boolForKey:@"pcmu_preference"]) { if(pt = [self findPayload:@"PCMU"withRate:8000 from:audioCodecs]) { - payload_type_set_enable(pt,TRUE); + linphone_core_enable_payload_type(myLinphoneCore,pt, TRUE); } } if ([[NSUserDefaults standardUserDefaults] boolForKey:@"pcma_preference"]) { if(pt = [self findPayload:@"PCMA"withRate:8000 from:audioCodecs]) { - payload_type_set_enable(pt,TRUE); + linphone_core_enable_payload_type(myLinphoneCore,pt, TRUE); } }