From 63272b2303d7dce9d5773a42525097b34c8bd307 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Wed, 21 Mar 2012 17:05:57 +0100 Subject: [PATCH] - fix crash with incoming calls on ios5.1 - play a sound during incoming calls in foreground. --- Classes/BuschJaegerAppDelegate.m | 7 +++-- Classes/BuschJaegerMainView.h | 3 ++ Classes/BuschJaegerMainView.m | 45 +++++++++++++++++++++++++++--- linphone.xcodeproj/project.pbxproj | 2 ++ 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/Classes/BuschJaegerAppDelegate.m b/Classes/BuschJaegerAppDelegate.m index e3c50676c..c77836e89 100644 --- a/Classes/BuschJaegerAppDelegate.m +++ b/Classes/BuschJaegerAppDelegate.m @@ -72,16 +72,19 @@ linphone_core_set_device_rotation([LinphoneManager getLc], 0); linphone_core_set_video_device([LinphoneManager getLc], "DummyImage: Dummy (no) picture"); - linphone_core_set_ring([LinphoneManager getLc], NULL ); - + linphone_core_set_ring([LinphoneManager getLc], NULL ); //so that we don't attempt to play ring by the core return YES; } - (void)applicationDidEnterBackground:(UIApplication *)application { + + [buschJaegerMainView activateVideoView:FALSE]; [[LinphoneManager instance] enterBackgroundMode]; } + - (void)applicationDidBecomeActive:(UIApplication *)application { [[LinphoneManager instance] becomeActive]; + [buschJaegerMainView activateVideoView:TRUE]; } - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { diff --git a/Classes/BuschJaegerMainView.h b/Classes/BuschJaegerMainView.h index 4477313a3..81bae2f00 100644 --- a/Classes/BuschJaegerMainView.h +++ b/Classes/BuschJaegerMainView.h @@ -25,6 +25,8 @@ #import "LinphoneManager.h" #import "UILightButton.h" +#define BJ_RING_FILE "01" + @interface BuschJaegerMainView : UIViewController { @private UIView* videoView; @@ -52,5 +54,6 @@ - (IBAction)takeCall:(id)sender; - (IBAction)startCall:(id)sender; +-(void) activateVideoView:(BOOL) value; @end diff --git a/Classes/BuschJaegerMainView.m b/Classes/BuschJaegerMainView.m index 8baa0f9bf..e8c3006e5 100644 --- a/Classes/BuschJaegerMainView.m +++ b/Classes/BuschJaegerMainView.m @@ -20,6 +20,7 @@ #import "BuschJaegerMainView.h" #include "linphonecore.h" #import +#import @implementation BuschJaegerMainView @@ -105,7 +106,6 @@ [LinphoneManager set:endOrRejectCall hidden:YES withName:"END_BTN" andReason:__FUNCTION__]; [LinphoneManager set:videoView hidden:YES withName:"VIDEO_VIEW" andReason:__FUNCTION__]; - linphone_core_set_native_video_window_id([LinphoneManager getLc],(unsigned long)videoView); if (!chatRoom) { NSString* s = [NSString stringWithFormat:@"sip:100000001@%@", [[NSUserDefaults standardUserDefaults] stringForKey:@"adapter_ip_preference"]]; @@ -115,6 +115,19 @@ lights->chatRoom = chatRoom; openDoor->chatRoom = chatRoom; } +} + +- (void) activateVideoView:(BOOL)value{ + if (value){ + linphone_core_set_native_video_window_id([LinphoneManager getLc],(unsigned long)videoView); + }else{ + linphone_core_set_native_video_window_id([LinphoneManager getLc],0); + linphone_core_set_native_preview_window_id([LinphoneManager getLc],0); + } + +} + +- (void) viewDidDisappear:(BOOL)animated{ } @@ -160,15 +173,38 @@ notif.repeatInterval = 0; notif.alertBody = NSLocalizedString(@" Ding Dong !",nil); notif.alertAction = @"See the answer"; - notif.soundName = @"01.wav"; + notif.soundName = @BJ_RING_FILE ".wav"; NSData *callData = [NSData dataWithBytes:&call length:sizeof(call)]; notif.userInfo = [NSDictionary dictionaryWithObject:callData forKey:@"call"]; [[UIApplication sharedApplication] presentLocalNotificationNow:notif]; } + }else{ + NSBundle* myBundle = [NSBundle mainBundle]; + + NSString* path = [myBundle pathForResource:@BJ_RING_FILE ofType:@"wav"]; + if (path) { + const char* soundfile = [path cStringUsingEncoding:[NSString defaultCStringEncoding]]; + ms_message("Using '%s' as ring file", soundfile); + SystemSoundID sid; + NSURL *pathURL = [NSURL fileURLWithPath : path]; + NSError *setCategoryError = nil; + [[AVAudioSession sharedInstance] + setCategory: AVAudioSessionCategoryAmbient + error: &setCategoryError]; + //redirect audio to speaker + UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker; + AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute + , sizeof (audioRouteOverride) + , &audioRouteOverride); + + AudioServicesCreateSystemSoundID((CFURLRef) pathURL, &sid); + AudioServicesPlaySystemSound(sid); + } + } - //linphone_call_enable_camera(call, FALSE); + linphone_call_enable_camera(call, FALSE); } - (void) displayVideoCall:(LinphoneCall *)call FromUI:(UIViewController *)viewCtrl forUser:(NSString *)username withDisplayName:(NSString *)displayName { @@ -178,6 +214,7 @@ [LinphoneManager set:decline hidden:YES withName:"DECLINE_BTN" andReason:__FUNCTION__]; [LinphoneManager set:endOrRejectCall hidden:NO withName:"END_BTN" andReason:__FUNCTION__]; [LinphoneManager set:videoView hidden:NO withName:"VIDEO_VIEW" andReason:__FUNCTION__]; + } - (void) displayStatus:(NSString *)message { @@ -229,7 +266,7 @@ ms_error("Failed to start a new call"); return; } - //linphone_call_enable_camera(lc, false); + linphone_call_enable_camera(lc, false); linphone_call_params_destroy(lcallParams); } diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index a47910ebe..d09407cc8 100755 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -1699,6 +1699,7 @@ armv6, ); CODE_SIGN_ENTITLEMENTS = untitled.plist; + CODE_SIGN_IDENTITY = "iPhone Distribution: jehan monnier"; COPY_PHASE_STRIP = NO; FRAMEWORK_SEARCH_PATHS = ""; GCC_DYNAMIC_NO_PIC = NO; @@ -1733,6 +1734,7 @@ ORDER_FILE = ""; OTHER_LDFLAGS = ""; PRODUCT_NAME = linphone; + PROVISIONING_PROFILE = "0FCDB3A2-9170-48DC-B1EE-58DF9948B0C7"; SDKROOT = iphoneos; STANDARD_C_PLUS_PLUS_LIBRARY_TYPE = dynamic; TARGETED_DEVICE_FAMILY = "1,2";