disable incoming call notification when call is declined

This commit is contained in:
Jehan Monnier 2011-01-31 16:54:56 +01:00
parent d5e083bf32
commit 05b1add5db
8 changed files with 116 additions and 113 deletions

View file

@ -29,7 +29,7 @@
@end
@class IncallViewController;
@interface PhoneViewController : UIViewController <UITextFieldDelegate,PhoneViewControllerDelegate> {
@interface PhoneViewController : UIViewController <UITextFieldDelegate,PhoneViewControllerDelegate,UIActionSheetDelegate> {
@private
//UI definition
@ -72,6 +72,8 @@
*/
LinphoneCore* mCore;
IncallViewController *myIncallViewController;
UIActionSheet *mIncomingCallActionSheet;
}
@property (nonatomic, retain) IBOutlet UITextField* address;

View file

@ -113,13 +113,7 @@
}
} else if (linphone_core_inc_invite_pending(mCore)) {
linphone_core_accept_call(mCore,linphone_core_get_current_call(mCore));
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_None;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute
, sizeof (audioRouteOverride)
, &audioRouteOverride);
}
//Cancel audio route redirection
} else if (sender == hangup) {
linphone_core_terminate_call(mCore,linphone_core_get_current_call(mCore));
@ -322,6 +316,82 @@
[status dealloc];
[super dealloc];
}
-(void) newIncomingCall:(NSString*) from {
//#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000
if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]
&& [UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
// Create a new notification
UILocalNotification* notif = [[[UILocalNotification alloc] init] autorelease];
if (notif)
{
notif.repeatInterval = 0;
notif.alertBody =[NSString stringWithFormat:@" %@ is calling you",from];
notif.alertAction = @"Answer";
notif.soundName = @"oldphone-mono-30s.caf";
[[UIApplication sharedApplication] presentLocalNotificationNow:notif];
}
} else
//#endif
{
mIncomingCallActionSheet = [[UIActionSheet alloc] initWithTitle:[NSString stringWithFormat:@" %@ is calling you",from]
delegate:self cancelButtonTitle:@"Decline" destructiveButtonTitle:@"Answer" otherButtonTitles:nil];
mIncomingCallActionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[mIncomingCallActionSheet showInView:self.view];
[mIncomingCallActionSheet release];
}
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0 ) {
linphone_core_accept_call(mCore,linphone_core_get_current_call(mCore));
} else {
linphone_core_terminate_call (mCore,linphone_core_get_current_call(mCore));
}
mIncomingCallActionSheet = nil;
}
-(void) enterIncallMode {
[hangup setEnabled:true];
[self muteAction:false];
// test if speaker must be unactivated after ring tone
if (!isSpeaker) [self speakerAction:false];
const LinphoneAddress* callAddress = linphone_call_get_remote_address(linphone_core_get_current_call(mCore));
const char* callDisplayName = linphone_address_get_display_name(callAddress)?linphone_address_get_display_name(callAddress):"";
if (callDisplayName && callDisplayName[0] != '\000') {
[peerLabel setText:[NSString stringWithCString:callDisplayName encoding:[NSString defaultCStringEncoding]]];
} else {
const char* username = linphone_address_get_username(callAddress)!=0?linphone_address_get_username(callAddress):"";
[peerLabel setText:[NSString stringWithCString:username encoding:[NSString defaultCStringEncoding]]];
}
// start scheduler
durationRefreasher = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(updateCallDuration)
userInfo:nil
repeats:YES];
[address setHidden:true];
[incallView setHidden:false];
if (linphone_call_get_dir(linphone_core_get_current_call(mCore)) == LinphoneCallOutgoing) {
[call setEnabled:false];
}
}
-(void) exitIncallMode {
[address setHidden:false];
[incallView setHidden:true];
[call setEnabled:true];
[hangup setEnabled:false];
if (durationRefreasher != nil) {
[ durationRefreasher invalidate];
durationRefreasher=nil;
}
[peerLabel setText:@""];
[callDuration setText:@""];
}
-(void) onCall:(LinphoneCall*) currentCall StateChanged: (LinphoneCallState) new_state withMessage: (const char *) message {
/*
@ -341,24 +411,38 @@
LinphoneCallEnd,
LinphoneCallPausedByRemote
*/
if (new_state != LinphoneCallIncomingReceived) {
if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]
&& [UIApplication sharedApplication].applicationState == UIApplicationStateBackground ) {
// cancel local notif if needed
[[UIApplication sharedApplication] cancelAllLocalNotifications];
} else {
if (mIncomingCallActionSheet) {
[mIncomingCallActionSheet dismissWithClickedButtonIndex:1 animated:true];
mIncomingCallActionSheet=nil;
}
}
}
switch (new_state) {
case LinphoneCallOutgoingInit:
case LinphoneCallIncomingReceived: {
[hangup setEnabled:true];
[self enterIncallMode];
[self newIncomingCall:[[NSString alloc] initWithCString:linphone_address_get_username(linphone_call_get_remote_address(currentCall))]];
break;
}
}
case LinphoneCallError: {
/*
NSString* lTitle= state->message!=nil?[NSString stringWithCString:state->message length:strlen(state->message)]: @"Error";
NSString* lMessage=lTitle;
*/
NSString* lTitle= state->message!=nil?[NSString stringWithCString:state->message length:strlen(state->message)]: @"Error";
NSString* lMessage=lTitle;
*/
NSString* lMessage;
NSString* lTitle;
lMessage=@"Please make sure your device is connected to the internet and double check your SIP account configuration in the settings.";
if (message!=nil){
lMessage=[NSString stringWithFormat : @"%@\nReason was: %s",lMessage, message];
}
@ -370,52 +454,14 @@
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[error show];
[self exitIncallMode];
//[self performSelector:@selector(dismissAlertDialog:) withObject:error afterDelay:2];
[self performSelector:@selector(dismissIncallView) withObject:nil afterDelay:2];
}
break;
case LinphoneCallConnected: {
[self muteAction:false];
// test if speaker must be unactivated after ring tone
if (!isSpeaker) [self speakerAction:false];
const LinphoneAddress* callAddress = linphone_call_get_remote_address(linphone_core_get_current_call(mCore));
const char* callDisplayName = linphone_address_get_display_name(callAddress)?linphone_address_get_display_name(callAddress):"";
if (callDisplayName && callDisplayName[0] != '\000') {
[peerLabel setText:[NSString stringWithCString:callDisplayName encoding:[NSString defaultCStringEncoding]]];
} else {
const char* username = linphone_address_get_username(callAddress)!=0?linphone_address_get_username(callAddress):"";
[peerLabel setText:[NSString stringWithCString:username encoding:[NSString defaultCStringEncoding]]];
}
// start scheduler
durationRefreasher = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(updateCallDuration)
userInfo:nil
repeats:YES];
[address setHidden:true];
[incallView setHidden:false];
[call setEnabled:false];
//[self performSelector:@selector(dismissIncallView) withObject:nil afterDelay:2];
break;
}
case LinphoneCallEnd: {
[address setHidden:false];
[incallView setHidden:true];
[call setEnabled:true];
[hangup setEnabled:false];
if (durationRefreasher != nil) {
[ durationRefreasher invalidate];
durationRefreasher=nil;
}
[peerLabel setText:@""];
[callDuration setText:@""];
[self exitIncallMode];
break;
}
default:
@ -454,5 +500,4 @@
isSpeaker=value;
};
@end

View file

@ -36,7 +36,7 @@
@class PhoneViewController;
@class CallHistoryTableViewController;
@interface linphoneAppDelegate : NSObject <UIApplicationDelegate,LinphoneTabManagerDelegate,UIActionSheetDelegate,UIAlertViewDelegate> {
@interface linphoneAppDelegate : NSObject <UIApplicationDelegate,LinphoneTabManagerDelegate,UIAlertViewDelegate> {
UIWindow *window;
IBOutlet UITabBarController* myTabBarController;
IBOutlet ABPeoplePickerNavigationController* myPeoplePickerController;
@ -55,8 +55,7 @@
SCNetworkReachabilityRef proxyReachability;
CFReadStreamRef mReadStream;
NSTimer* mIterateTimer;
}
/**********************************
* liblinphone initialization method

View file

@ -58,12 +58,6 @@ void linphone_iphone_display_status(struct _LinphoneCore * lc, const char * mess
void linphone_iphone_call_state(LinphoneCore *lc, LinphoneCall* call, LinphoneCallState state,const char* message) {
linphoneAppDelegate* lAppDelegate = (linphoneAppDelegate*) linphone_core_get_user_data(lc);
if (state == LinphoneCallIncomingReceived) {
[lAppDelegate newIncomingCall:[[NSString alloc] initWithCString:linphone_address_get_username(linphone_call_get_remote_address(call))]];
} else if (lAppDelegate.backgroundSupported && [UIApplication sharedApplication].applicationState == UIApplicationStateBackground && (LinphoneCallEnd|LinphoneCallError)) {
// cancel local notif if needed
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
PhoneViewController* lPhone = lAppDelegate.myPhoneViewController;
[lPhone onCall:call StateChanged:state withMessage:message];
}
@ -600,47 +594,8 @@ extern void libmsilbc_init();
}
-(void) newIncomingCall:(NSString*) from {
//redirect audio to speaker
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute
, sizeof (audioRouteOverride)
, &audioRouteOverride);
//#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000
if (backgroundSupported && [UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
// Create a new notification
UILocalNotification* notif = [[[UILocalNotification alloc] init] autorelease];
if (notif)
{
notif.repeatInterval = 0;
notif.alertBody =[NSString stringWithFormat:@" %@ is calling you",from];
notif.alertAction = @"Answer";
notif.soundName = @"oldphone-mono-30s.caf";
[[UIApplication sharedApplication] presentLocalNotificationNow:notif];
}
} else
//#endif
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:[NSString stringWithFormat:@" %@ is calling you",from]
delegate:self cancelButtonTitle:@"Decline" destructiveButtonTitle:@"Answer" otherButtonTitles:nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showFromTabBar:myTabBarController.tabBar];
[actionSheet release];
}
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0 ) {
linphone_core_accept_call(myLinphoneCore,linphone_core_get_current_call(myLinphoneCore));
} else {
linphone_core_terminate_call (myLinphoneCore,linphone_core_get_current_call(myLinphoneCore));
}
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
linphone_core_accept_call(myLinphoneCore,linphone_core_get_current_call(myLinphoneCore));

View file

@ -36,6 +36,7 @@
2245671D107699F700F10948 /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 2245671C107699F700F10948 /* Settings.bundle */; };
224567C2107B968500F10948 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 224567C1107B968500F10948 /* AVFoundation.framework */; };
2245F78A1201D38000C4179D /* MoreViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 22E0A81B111C44E100B04932 /* MoreViewController.xib */; };
2252941412F6DAA400DD9BFB /* libmediastreamer.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 220FAD2B10765B400068D98F /* libmediastreamer.a */; };
225CB2EA11ABB51000628906 /* clavier-01-106px.png in Resources */ = {isa = PBXBuildFile; fileRef = 225CB2E811ABB51000628906 /* clavier-01-106px.png */; };
225CB2EB11ABB51000628906 /* clavier-01-108px.png in Resources */ = {isa = PBXBuildFile; fileRef = 225CB2E911ABB51000628906 /* clavier-01-108px.png */; };
225CB2EE11ABB65D00628906 /* clavier-01-160px.png in Resources */ = {isa = PBXBuildFile; fileRef = 225CB2ED11ABB65D00628906 /* clavier-01-160px.png */; };
@ -47,7 +48,6 @@
227BCDC210D4004600FBFD76 /* CallHistoryTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 227BCDC010D4004600FBFD76 /* CallHistoryTableViewController.m */; };
227BCDC310D4004600FBFD76 /* CallHistoryTableViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 227BCDC110D4004600FBFD76 /* CallHistoryTableViewController.xib */; };
228697C411AC29B800E9E0CA /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 228697C311AC29B800E9E0CA /* CFNetwork.framework */; };
22A10F3A11F8960300373793 /* libmediastreamer.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 220FAD2B10765B400068D98F /* libmediastreamer.a */; };
22A10F3B11F8960300373793 /* libortp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 220FAD2C10765B400068D98F /* libortp.a */; };
22B5EFA310CE50BD00777D97 /* AddressBookUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22B5EFA210CE50BD00777D97 /* AddressBookUI.framework */; };
22B5EFE510CE5E5800777D97 /* ContactPickerDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 22B5EFE410CE5E5800777D97 /* ContactPickerDelegate.m */; };
@ -227,7 +227,6 @@
2242E312125235120061DDCE /* oldphone-mono-30s.caf */ = {isa = PBXFileReference; lastKnownFileType = file; name = "oldphone-mono-30s.caf"; path = "liblinphone-sdk/apple-darwin/share/sounds/linphone/rings/oldphone-mono-30s.caf"; sourceTree = "<group>"; };
2245671C107699F700F10948 /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = "<group>"; };
224567C1107B968500F10948 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
2245F77E1201D2AF00C4179D /* linphone-Info copy.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "linphone-Info copy.plist"; sourceTree = "<group>"; };
2258633C11410BAC00C5A737 /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
225CB2E811ABB51000628906 /* clavier-01-106px.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "clavier-01-106px.png"; path = "Resources/clavier-01-106px.png"; sourceTree = "<group>"; };
225CB2E911ABB51000628906 /* clavier-01-108px.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "clavier-01-108px.png"; path = "Resources/clavier-01-108px.png"; sourceTree = "<group>"; };
@ -291,9 +290,9 @@
223148E41178A08200637D6A /* libilbc.a in Frameworks */,
223148E61178A09900637D6A /* libmsilbc.a in Frameworks */,
228697C411AC29B800E9E0CA /* CFNetwork.framework in Frameworks */,
22A10F3A11F8960300373793 /* libmediastreamer.a in Frameworks */,
22A10F3B11F8960300373793 /* libortp.a in Frameworks */,
22D1B68112A3E0BE001AE361 /* libresolv.dylib in Frameworks */,
2252941412F6DAA400DD9BFB /* libmediastreamer.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -599,7 +598,6 @@
8D1107310486CEB800E47090 /* linphone-Info.plist */,
2274550710700509006EC466 /* linphonerc */,
220FAE4A10767A6A0068D98F /* PhoneMainView.xib */,
2245F77E1201D2AF00C4179D /* linphone-Info copy.plist */,
);
name = Resources;
sourceTree = "<group>";

View file

@ -14,7 +14,7 @@ use_ipv6=0
default_proxy=-1
register_only_when_network_is_up=1
auto_net_state_mon=0
keepalive_period=3600000
keepalive_period=30000
[rtp]
audio_rtp_port=7076
@ -24,8 +24,8 @@ video_jitt_comp=60
nortp_timeout=30
[sound]
playback_dev_id=AU: Audio Unit
ringer_dev_id=AU: Audio Unit
capture_dev_id=AU: Audio Unit
playback_dev_id=AU: Audio Unit Receiver
ringer_dev_id=AU: Audio Unit Speaker
capture_dev_id=AU: Audio Unit Receiver

View file

@ -149,6 +149,7 @@
222CA78411F6CFB100621220 /* siplogin.c in Sources */ = {isa = PBXBuildFile; fileRef = 222CA76211F6CFB100621220 /* siplogin.c */; };
222CA78511F6CFB100621220 /* sipsetup.c in Sources */ = {isa = PBXBuildFile; fileRef = 222CA76311F6CFB100621220 /* sipsetup.c */; };
222CA78611F6CFB100621220 /* sipsetup.h in Headers */ = {isa = PBXBuildFile; fileRef = 222CA76411F6CFB100621220 /* sipsetup.h */; };
2252935B12F6CA4700DD9BFB /* ec-calibrator.c in Sources */ = {isa = PBXBuildFile; fileRef = 2252935A12F6CA4700DD9BFB /* ec-calibrator.c */; };
225D355A124B1FF60008581C /* linphonecall.c in Sources */ = {isa = PBXBuildFile; fileRef = 225D3559124B1FF60008581C /* linphonecall.c */; };
22A10B5611F84E2D00373793 /* config.h in Headers */ = {isa = PBXBuildFile; fileRef = 22A10B4F11F84E2D00373793 /* config.h */; };
22A10B5711F84E2D00373793 /* gsm.h in Headers */ = {isa = PBXBuildFile; fileRef = 22A10B5011F84E2D00373793 /* gsm.h */; };
@ -330,6 +331,7 @@
222CA76211F6CFB100621220 /* siplogin.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = siplogin.c; sourceTree = "<group>"; };
222CA76311F6CFB100621220 /* sipsetup.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sipsetup.c; sourceTree = "<group>"; };
222CA76411F6CFB100621220 /* sipsetup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sipsetup.h; sourceTree = "<group>"; };
2252935A12F6CA4700DD9BFB /* ec-calibrator.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "ec-calibrator.c"; path = "linphone/coreapi/ec-calibrator.c"; sourceTree = SOURCE_ROOT; };
225D3559124B1FF60008581C /* linphonecall.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = linphonecall.c; sourceTree = "<group>"; };
22A10B4F11F84E2D00373793 /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; };
22A10B5011F84E2D00373793 /* gsm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = gsm.h; sourceTree = "<group>"; };
@ -474,6 +476,7 @@
222CA5DC11F6CF7600621220 /* src */ = {
isa = PBXGroup;
children = (
2252935A12F6CA4700DD9BFB /* ec-calibrator.c */,
222CA5DD11F6CF7600621220 /* .gitignore */,
222CA5DE11F6CF7600621220 /* _kiss_fft_guts.h */,
222CA5DF11F6CF7600621220 /* alaw.c */,
@ -901,6 +904,7 @@
222CA78511F6CFB100621220 /* sipsetup.c in Sources */,
22A10EE811F8920F00373793 /* mswebcam.c in Sources */,
225D355A124B1FF60008581C /* linphonecall.c in Sources */,
2252935B12F6CA4700DD9BFB /* ec-calibrator.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

@ -1 +1 @@
Subproject commit 224e90104d6a360cdbc39029c81b944a7ca43543
Subproject commit fd5e9b931875505c10be591afa83a11b4b813b40