diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 6226d7bff..4ee7534ca 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -241,9 +241,18 @@ } - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { - [[UIApplication sharedApplication] cancelLocalNotification:notification]; + + [self fixRing]; + + if([notification.userInfo objectForKey:@"callId"] != nil) { - [[LinphoneManager instance] acceptCallForCallId:[notification.userInfo objectForKey:@"callId"]]; + // some local notifications have an internal timer to relaunch themselves at specified intervals + if( [[notification.userInfo objectForKey:@"timer"] intValue] == 1 ){ + [[LinphoneManager instance] cancelLocalNotifTimerForCallId:[notification.userInfo objectForKey:@"callId"]]; + } else { + // auto answer only for non-timed local notifications + [[LinphoneManager instance] acceptCallForCallId:[notification.userInfo objectForKey:@"callId"]]; + } } else if([notification.userInfo objectForKey:@"chat"] != nil) { NSString *remoteContact = (NSString*)[notification.userInfo objectForKey:@"chat"]; // Go to ChatRoom view diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index df20cbaf2..b0b72c731 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -82,6 +82,7 @@ struct NetworkReachabilityContext { UILocalNotification *notification; NSMutableDictionary *userInfos; bool_t videoRequested; /*set when user has requested for video*/ + NSTimer* timer; }; @end @@ -130,6 +131,7 @@ typedef struct _LinphoneManagerSounds { - (void)addPushTokenToProxyConfig: (LinphoneProxyConfig*)cfg; - (BOOL)shouldAutoAcceptCallForCallId:(NSString*) callId; - (void)acceptCallForCallId:(NSString*)callid; +- (void)cancelLocalNotifTimerForCallId:(NSString*)callid; - (void)waitForRegisterToArrive; + (void)kickOffNetworkConnection; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 752f99051..92314ade7 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -438,6 +438,14 @@ static void linphone_iphone_display_status(struct _LinphoneCore * lc, const char #pragma mark - Call State Functions +- (void)localNotifContinue:(NSTimer*) timer { + UILocalNotification* notif = [timer userInfo]; + if (notif){ + [[UIApplication sharedApplication] cancelLocalNotification:notif]; + [[UIApplication sharedApplication] presentLocalNotificationNow:notif]; + } +} + - (void)onCall:(LinphoneCall*)call StateChanged:(LinphoneCallState)state withMessage:(const char *)message { // Handling wrapper @@ -513,18 +521,23 @@ static void linphone_iphone_display_status(struct _LinphoneCore * lc, const char // Create a new local notification data->notification = [[UILocalNotification alloc] init]; if (data->notification) { - data->notification.repeatInterval = 0; + data->timer = [NSTimer scheduledTimerWithTimeInterval:4.0 target:self selector:@selector(localNotifContinue:) userInfo:data->notification repeats:TRUE]; + + data->notification.repeatInterval = 0; data->notification.alertBody =[NSString stringWithFormat:NSLocalizedString(@"IC_MSG",nil), address]; data->notification.alertAction = NSLocalizedString(@"Answer", nil); data->notification.soundName = @"ring.caf"; - data->notification.userInfo = [NSDictionary dictionaryWithObject:callId forKey:@"callId"]; - + data->notification.userInfo = @{@"callId": callId, @"timer":[NSNumber numberWithInt:1] }; + data->notification.applicationIconBadgeNumber = 1; + [[UIApplication sharedApplication] presentLocalNotificationNow:data->notification]; if (!incallBgTask){ incallBgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler: ^{ [LinphoneLogger log:LinphoneLoggerWarning format:@"Call cannot ring any more, too late"]; }]; + + [[NSRunLoop currentRunLoop] addTimer:data->timer forMode:NSRunLoopCommonModes]; } } @@ -551,6 +564,10 @@ static void linphone_iphone_display_status(struct _LinphoneCore * lc, const char // cancel local notif if needed [[UIApplication sharedApplication] cancelLocalNotification:data->notification]; + if( data->timer ){ + [data->timer invalidate]; + data->timer = nil; + } [data->notification release]; data->notification = nil; @@ -1171,6 +1188,21 @@ static int comp_call_id(const LinphoneCall* call , const char *callid) { return strcmp(linphone_call_log_get_call_id(linphone_call_get_call_log(call)), callid); } +- (void)cancelLocalNotifTimerForCallId:(NSString*)callid { + //first, make sure this callid is not already involved in a call + if ([LinphoneManager isLcReady]) { + MSList* calls = (MSList*)linphone_core_get_calls(theLinphoneCore); + MSList* call = ms_list_find_custom(calls, (MSCompareFunc)comp_call_id, [callid UTF8String]); + if (call != NULL) { + LinphoneCallAppData* data = linphone_call_get_user_pointer((LinphoneCall*)call->data); + if( data->timer ) + [data->timer invalidate]; + data->timer = nil; + return; + } + } +} + - (void)acceptCallForCallId:(NSString*)callid { //first, make sure this callid is not already involved in a call if ([LinphoneManager isLcReady]) { diff --git a/Resources/shortring.caf b/Resources/shortring.caf new file mode 100644 index 000000000..c3d9bc24a Binary files /dev/null and b/Resources/shortring.caf differ diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index f16cbd3a5..ab3b466d3 100755 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -1344,6 +1344,8 @@ F01A77C518EBEC6200E287CA /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F0B89C2118DC89E30050B60E /* MediaPlayer.framework */; }; F01A77C618EBECCB00E287CA /* libc++.1.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 344ABDEF14850AE9007420B6 /* libc++.1.dylib */; settings = {ATTRIBUTES = (Weak, ); }; }; F01A77C718EBECEA00E287CA /* libstdc++.6.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 344ABDF014850AE9007420B6 /* libstdc++.6.dylib */; settings = {ATTRIBUTES = (Weak, ); }; }; + F01A77EB18ED989B00E287CA /* shortring.caf in Resources */ = {isa = PBXBuildFile; fileRef = F01A77EA18ED989B00E287CA /* shortring.caf */; }; + F01A77EC18ED989B00E287CA /* shortring.caf in Resources */ = {isa = PBXBuildFile; fileRef = F01A77EA18ED989B00E287CA /* shortring.caf */; }; F03A9B1D18C0CF7000C4D7FE /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; }; F03A9B1E18C0CF7000C4D7FE /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 288765FC0DF74451002DB57D /* CoreGraphics.framework */; }; F03A9B1F18C0CF7000C4D7FE /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; }; @@ -2464,6 +2466,7 @@ D3F9A9EC15AF277D0045320F /* UACellBackgroundView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UACellBackgroundView.h; path = Utils/UACellBackgroundView/UACellBackgroundView.h; sourceTree = ""; }; D3F9A9ED15AF277D0045320F /* UACellBackgroundView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = UACellBackgroundView.m; path = Utils/UACellBackgroundView/UACellBackgroundView.m; sourceTree = ""; }; F0181B6B18BF7B1200A9A357 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; }; + F01A77EA18ED989B00E287CA /* shortring.caf */ = {isa = PBXFileReference; lastKnownFileType = file; name = shortring.caf; path = Resources/shortring.caf; sourceTree = ""; }; F03A9B1C18C0CF7000C4D7FE /* linphonetester.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = linphonetester.app; sourceTree = BUILT_PRODUCTS_DIR; }; F03A9B2218C0CF7000C4D7FE /* tester-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "tester-Info.plist"; sourceTree = ""; }; F03A9B2418C0CF7000C4D7FE /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; @@ -3395,6 +3398,7 @@ D3804E5E15D92A57008072A5 /* msg.caf */, D3804E5F15D92A57008072A5 /* msg.wav */, 2242E312125235120061DDCE /* ring.caf */, + F01A77EA18ED989B00E287CA /* shortring.caf */, 2237D4081084D7A9001383EE /* ring.wav */, 22F254801073D99800AC9B3F /* ringback.wav */, 70571E1913FABCB000CDD3C2 /* rootca.pem */, @@ -4824,6 +4828,7 @@ D3F83F1E158205A100336684 /* speaker_off_over.png in Resources */, D3F83F20158205A100336684 /* speaker_on_default.png in Resources */, D3F83F22158205A100336684 /* speaker_on_over.png in Resources */, + F01A77EB18ED989B00E287CA /* shortring.caf in Resources */, D3F83F24158205A100336684 /* video_off_default.png in Resources */, D3F83F26158205A100336684 /* video_off_over.png in Resources */, D3F83F28158205A100336684 /* video_on_default.png in Resources */, @@ -5369,6 +5374,7 @@ D34BD72F15C13DD40070C209 /* LinphoneApp.xib in Resources */, D34BD73015C13DD40070C209 /* AboutViewController.xib in Resources */, D34BD73115C13DD40070C209 /* PhoneMainView.xib in Resources */, + F01A77EC18ED989B00E287CA /* shortring.caf in Resources */, D34BD73215C13DD40070C209 /* SettingsViewController.xib in Resources */, D38187DE15FE348A00C3EDCA /* WizardViewController.xib in Resources */, D34BD62815C13DB60070C209 /* back_over.png in Resources */,