diff --git a/Classes/ChatRoomViewController.m b/Classes/ChatRoomViewController.m index 36c5247c1..fbcf1ab8e 100644 --- a/Classes/ChatRoomViewController.m +++ b/Classes/ChatRoomViewController.m @@ -448,8 +448,7 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta if(fromStr && cr_from_string ) { if(strcasecmp(cr_from_string, fromStr) == 0) { - if (![[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] - || [UIApplication sharedApplication].applicationState == UIApplicationStateActive) { + if ([UIApplication sharedApplication].applicationState != UIApplicationStateBackground) { linphone_chat_room_mark_as_read(room); [[NSNotificationCenter defaultCenter] postNotificationName:kLinphoneTextReceived object:self]; } diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 9a84cf260..00f92b401 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -55,18 +55,17 @@ - (void)applicationDidEnterBackground:(UIApplication *)application{ - [LinphoneLogger logc:LinphoneLoggerLog format:"applicationDidEnterBackground"]; + Linphone_log(@"%@", NSStringFromSelector(_cmd)); if(![LinphoneManager isLcReady]) return; [[LinphoneManager instance] enterBackgroundMode]; } - (void)applicationWillResignActive:(UIApplication *)application { - [LinphoneLogger logc:LinphoneLoggerLog format:"applicationWillResignActive"]; + Linphone_log(@"%@", NSStringFromSelector(_cmd)); if(![LinphoneManager isLcReady]) return; LinphoneCore* lc = [LinphoneManager getLc]; LinphoneCall* call = linphone_core_get_current_call(lc); - if (call){ /* save call context */ LinphoneManager* instance = [LinphoneManager instance]; @@ -86,8 +85,8 @@ } - (void)applicationDidBecomeActive:(UIApplication *)application { - [LinphoneLogger logc:LinphoneLoggerLog format:"applicationDidBecomeActive"]; - + Linphone_log(@"%@", NSStringFromSelector(_cmd)); + [self startApplication]; if( startedInBackground ){ startedInBackground = FALSE; @@ -197,8 +196,7 @@ BOOL start_at_boot = [instance lpConfigBoolForKey:@"start_at_boot_preference"]; - if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] - && state == UIApplicationStateBackground) + if (state == UIApplicationStateBackground) { // we've been woken up directly to background; if( !start_at_boot || !background_mode ) { @@ -244,7 +242,7 @@ } - (void)applicationWillTerminate:(UIApplication *)application { - [LinphoneLogger log:LinphoneLoggerLog format:@"Application Will Terminate"]; + Linphone_log(@"%@", NSStringFromSelector(_cmd)); } - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { @@ -323,8 +321,8 @@ } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { - [LinphoneLogger log:LinphoneLoggerLog format:@"PushNotification: Receive %@", userInfo]; - + Linphone_log(@"%@ : %@", NSStringFromSelector(_cmd), userInfo); + [self processRemoteNotification:userInfo]; } @@ -343,12 +341,13 @@ } - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { + Linphone_log(@"%@ - state = %d", NSStringFromSelector(_cmd), application.applicationState); [self fixRing]; - if([notification.userInfo objectForKey:@"callId"] != nil) { BOOL auto_answer = TRUE; + // 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"]]; @@ -381,6 +380,7 @@ // this method is implemented for iOS7. It is invoked when receiving a push notification for a call and it has "content-available" in the aps section. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { + Linphone_log(@"%@ : %@", NSStringFromSelector(_cmd), userInfo); LinphoneManager* lm = [LinphoneManager instance]; if (lm.pushNotificationToken==Nil){ @@ -392,7 +392,6 @@ if( ![LinphoneManager isLcReady] ) [lm startLibLinphone]; - [LinphoneLogger log:LinphoneLoggerLog format:@"Silent PushNotification; userInfo %@", userInfo]; // save the completion handler for later execution. // 2 outcomes: @@ -415,22 +414,23 @@ #pragma mark - PushNotification Functions - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken { - [LinphoneLogger log:LinphoneLoggerLog format:@"PushNotification: Token %@", deviceToken]; + Linphone_log(@"%@ : %@", NSStringFromSelector(_cmd), deviceToken); [[LinphoneManager instance] setPushNotificationToken:deviceToken]; } - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error { - [LinphoneLogger log:LinphoneLoggerError format:@"PushNotification: Error %@", [error localizedDescription]]; + Linphone_log(@"%@ : %@", NSStringFromSelector(_cmd), [error localizedDescription]); [[LinphoneManager instance] setPushNotificationToken:nil]; } #pragma mark - User notifications - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { - [LinphoneLogger log:LinphoneLoggerLog format:@"%@", NSStringFromSelector(_cmd)]; + Linphone_log(@"%@", NSStringFromSelector(_cmd)); } - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler { + Linphone_log(@"%@", NSStringFromSelector(_cmd)); if( [[UIDevice currentDevice].systemVersion floatValue] >= 8){ LinphoneCore* lc = [LinphoneManager getLc]; @@ -461,6 +461,7 @@ } - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler { + Linphone_log(@"%@", NSStringFromSelector(_cmd)); completionHandler(); } diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 293a6389a..c3c603f81 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -656,8 +656,7 @@ static void linphone_iphone_display_status(struct _LinphoneCore * lc, const char } [lCTCallCenter release]; - if( [[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] - && [UIApplication sharedApplication].applicationState != UIApplicationStateActive) { + if( [UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { LinphoneCallLog* callLog=linphone_call_get_call_log(call); NSString* callId=[NSString stringWithUTF8String:linphone_call_log_get_call_id(callLog)]; @@ -871,8 +870,7 @@ static void linphone_iphone_registration_state(LinphoneCore *lc, LinphoneProxyCo silentPushCompletion = nil; } - if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] - && [UIApplication sharedApplication].applicationState != UIApplicationStateActive) { + if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { const LinphoneAddress* remoteAddress = linphone_chat_message_get_from_address(msg); char* c_address = linphone_address_as_string_uri_only(remoteAddress); @@ -1291,8 +1289,7 @@ static BOOL libStarted = FALSE; [error release]; } - if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] - && [UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { + if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { //go directly to bg mode [self enterBackgroundMode]; } diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index 921cde416..1eb161ce3 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -305,7 +305,7 @@ static RootViewManager* rootViewManagerInstance = nil; LinphoneProxyConfig *cfg = [[notif.userInfo objectForKey: @"cfg"] pointerValue]; //Only report bad credential issue if (state == LinphoneRegistrationFailed - &&[UIApplication sharedApplication].applicationState != UIApplicationStateBackground + &&[UIApplication sharedApplication].applicationState == UIApplicationStateBackground && linphone_proxy_config_get_error(cfg) == LinphoneReasonBadCredentials ) { UIAlertView* error = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Registration failure",nil) message:NSLocalizedString(@"Bad credentials, check your account settings", nil) @@ -673,8 +673,7 @@ static RootViewManager* rootViewManagerInstance = nil; #pragma mark - ActionSheet Functions - (void)playMessageSound { - if (![[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] - || [UIApplication sharedApplication].applicationState == UIApplicationStateActive) { + if ([UIApplication sharedApplication].applicationState != UIApplicationStateBackground) { if(![self removeInhibitedEvent:kLinphoneTextReceived]) { AudioServicesPlaySystemSound([LinphoneManager instance].sounds.message); AudioServicesPlaySystemSound([LinphoneManager instance].sounds.vibrate); @@ -686,12 +685,17 @@ static RootViewManager* rootViewManagerInstance = nil; LinphoneCallLog* callLog=linphone_call_get_call_log(call); NSString* callId=[NSString stringWithUTF8String:linphone_call_log_get_call_id(callLog)]; - if (![[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] - || [UIApplication sharedApplication].applicationState == UIApplicationStateActive) { + if ([UIApplication sharedApplication].applicationState != UIApplicationStateBackground) { if ([[LinphoneManager instance] shouldAutoAcceptCallForCallId:callId]){ [[LinphoneManager instance] acceptCall:call]; - }else{ - IncomingCallViewController *controller = DYNAMIC_CAST([self changeCurrentView:[IncomingCallViewController compositeViewDescription] push:TRUE],IncomingCallViewController); + }else { + IncomingCallViewController *controller = nil; + if( ![currentView.name isEqualToString:[IncomingCallViewController compositeViewDescription].name]){ + controller = DYNAMIC_CAST([self changeCurrentView:[IncomingCallViewController compositeViewDescription] push:TRUE],IncomingCallViewController); + } else { + // controller is already presented, don't bother animating a transition + controller = DYNAMIC_CAST([self.mainViewController getCurrentViewController],IncomingCallViewController); + } AudioServicesPlaySystemSound([LinphoneManager instance].sounds.vibrate); if(controller != nil) { [controller setCall:call];