From f3ce7ada2d00ca72776e8f7d7a60b4a796cef1a6 Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Wed, 19 Apr 2017 16:04:59 +0200 Subject: [PATCH] Better management of app states --- Classes/CallView.m | 6 +- Classes/ChatConversationTableView.m | 3 +- Classes/ChatConversationView.m | 3 +- Classes/InAppProductsManager.m | 2 +- Classes/LinphoneAppDelegate.m | 82 +-------- Classes/LinphoneManager.m | 206 +++++++++++----------- Classes/LinphoneUI/StatusBarView.m | 2 +- Classes/LinphoneUI/UIChatBubbleTextCell.m | 3 +- Classes/PhoneMainView.m | 6 +- Classes/ProviderDelegate.m | 14 +- 10 files changed, 126 insertions(+), 201 deletions(-) diff --git a/Classes/CallView.m b/Classes/CallView.m index c922897a1..bfb54521f 100644 --- a/Classes/CallView.m +++ b/Classes/CallView.m @@ -567,7 +567,7 @@ static void hideSpinner(LinphoneCall *call, void *user_data) { if ((linphone_core_video_display_enabled(LC) && !linphone_call_params_video_enabled(current) && linphone_call_params_video_enabled(remote)) && (!linphone_core_get_video_policy(LC)->automatically_accept || - (([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) && + (([UIApplication sharedApplication].applicationState != UIApplicationStateActive) && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max))) { linphone_core_defer_call_update(LC, call); [self displayAskToEnableVideoCall:call]; @@ -600,12 +600,12 @@ static void hideSpinner(LinphoneCall *call, void *user_data) { return; } if (linphone_core_get_video_policy(LC)->automatically_accept && - !([UIApplication sharedApplication].applicationState == UIApplicationStateBackground)) + !([UIApplication sharedApplication].applicationState != UIApplicationStateActive)) return; NSString *username = [FastAddressBook displayNameForAddress:linphone_call_get_remote_address(call)]; NSString *title = [NSString stringWithFormat:NSLocalizedString(@"%@ would like to enable video", nil), username]; - if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground && + if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max) { UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; content.title = NSLocalizedString(@"Video request", nil); diff --git a/Classes/ChatConversationTableView.m b/Classes/ChatConversationTableView.m index c13f906e9..6e5747caf 100644 --- a/Classes/ChatConversationTableView.m +++ b/Classes/ChatConversationTableView.m @@ -130,8 +130,7 @@ if (index == -1 && count > 0) { index = (int)count - 1; } - if (!([UIApplication sharedApplication].applicationState == UIApplicationStateBackground || - [UIApplication sharedApplication].applicationState == UIApplicationStateInactive)) { + if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) { linphone_chat_room_mark_as_read(_chatRoom); } TabBarView *tab = (TabBarView *)[PhoneMainView.instance.mainViewController diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 953a1aaa2..41a404042 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -358,8 +358,7 @@ static UICompositeViewDescription *compositeDescription = nil; if (fromStr && cr_from_string) { if (strcasecmp(cr_from_string, fromStr) == 0) { - if (!([UIApplication sharedApplication].applicationState == UIApplicationStateBackground || - [UIApplication sharedApplication].applicationState == UIApplicationStateInactive)) { + if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) { linphone_chat_room_mark_as_read(room); } [NSNotificationCenter.defaultCenter postNotificationName:kLinphoneMessageReceived object:self]; diff --git a/Classes/InAppProductsManager.m b/Classes/InAppProductsManager.m index 412afbdb3..d367464b3 100644 --- a/Classes/InAppProductsManager.m +++ b/Classes/InAppProductsManager.m @@ -404,7 +404,7 @@ expireText = [NSString stringWithFormat:NSLocalizedString(@"Your account has expired.", nil), days]; } - if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground){ + if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { UILocalNotification *notification = [[UILocalNotification alloc] init]; if (notification) { diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index c64e089ad..03265eebc 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -306,7 +306,7 @@ [LinphoneManager.instance setProviderDelegate:self.del]; } - if (state == UIApplicationStateBackground) { + if (state != UIApplicationStateActive) { // we've been woken up directly to background; if (!start_at_boot || !background_mode) { // autoboot disabled or no background, and no push: do nothing and wait for a real launch @@ -470,7 +470,7 @@ } if (callId && [self addLongTaskIDforCallID:callId]) { - if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground && loc_key && + if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive && loc_key && index > 0) { if ([loc_key isEqualToString:@"IC_MSG"]) { [LinphoneManager.instance startPushLongRunningTask:FALSE]; @@ -515,78 +515,6 @@ return NULL; } -/* -- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { - LOGI(@"%@ - state = %ld", NSStringFromSelector(_cmd), (long)application.applicationState); - - if ([notification.category isEqual:LinphoneManager.instance.iapManager.notificationCategory]){ - [PhoneMainView.instance changeCurrentView:ShopView.compositeViewDescription]; - return; - } - - [self fixRing]; - - if ([notification.userInfo objectForKey:@"callId"] != nil) { - BOOL bypass_incoming_view = 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"]]; - bypass_incoming_view = [LinphoneManager.instance lpConfigBoolForKey:@"autoanswer_notif_preference"]; - } - if (bypass_incoming_view) { - [LinphoneManager.instance acceptCallForCallId:[notification.userInfo objectForKey:@"callId"]]; - } - } else if ([notification.userInfo objectForKey:@"from_addr"] != nil) { - NSString *chat = notification.alertBody; - NSString *remote_uri = (NSString *)[notification.userInfo objectForKey:@"from_addr"]; - NSString *from = (NSString *)[notification.userInfo objectForKey:@"from"]; - NSString *callID = (NSString *)[notification.userInfo objectForKey:@"call-id"]; - LinphoneChatRoom *room = [self findChatRoomForContact:remote_uri]; - if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground || - ((PhoneMainView.instance.currentView != ChatsListView.compositeViewDescription) && - ((PhoneMainView.instance.currentView != ChatConversationView.compositeViewDescription))) || - (PhoneMainView.instance.currentView == ChatConversationView.compositeViewDescription && - room != PhoneMainView.instance.currentRoom)) { - // Create a new notification - - if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) { - // Do nothing - } else { - UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; - content.title = NSLocalizedString(@"Message received", nil); - if ([LinphoneManager.instance lpConfigBoolForKey:@"show_msg_in_notif" withDefault:YES]) { - content.subtitle = from; - content.body = chat; - } else { - content.body = from; - } - content.sound = [UNNotificationSound soundNamed:@"msg.caf"]; - content.categoryIdentifier = @"msg_cat"; - content.userInfo = @{ @"from" : from, @"from_addr" : remote_uri, @"call-id" : callID }; - content.accessibilityLabel = @"Message notif"; - UNNotificationRequest *req = - [UNNotificationRequest requestWithIdentifier:@"call_request" content:content trigger:NULL]; - req.accessibilityLabel = @"Message notif"; - [[UNUserNotificationCenter currentNotificationCenter] - addNotificationRequest:req - withCompletionHandler:^(NSError *_Nullable error) { - // Enable or disable features based on authorization. - if (error) { - LOGD(@"Error while adding notification request :"); - LOGD(error.description); - } - }]; - } - } - } else if ([notification.userInfo objectForKey:@"callLog"] != nil) { - NSString *callLog = (NSString *)[notification.userInfo objectForKey:@"callLog"]; - HistoryDetailsView *view = VIEW(HistoryDetailsView); - [view setCallLogId:callLog]; - [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; - } -} -*/ - #pragma mark - PushNotification Functions - (void)application:(UIApplication *)application @@ -903,8 +831,7 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response NSString *from = [notification.userInfo objectForKey:@"from_addr"]; LinphoneChatRoom *room = linphone_core_get_chat_room_from_uri(LC, [from UTF8String]); if (room) { - if (!([UIApplication sharedApplication].applicationState == UIApplicationStateBackground || - [UIApplication sharedApplication].applicationState == UIApplicationStateInactive)) + if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) linphone_chat_room_mark_as_read(room); TabBarView *tab = (TabBarView *)[PhoneMainView.instance.mainViewController getCachedController:NSStringFromClass(TabBarView.class)]; @@ -954,8 +881,7 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response if (linphone_core_lime_enabled(LC) == LinphoneLimeMandatory && !linphone_chat_room_lime_available(room)) { [LinphoneManager.instance alertLIME:room]; } - if (!([UIApplication sharedApplication].applicationState == UIApplicationStateBackground || - [UIApplication sharedApplication].applicationState == UIApplicationStateInactive)) { + if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) { linphone_chat_room_mark_as_read(room); } [PhoneMainView.instance updateApplicationBadgeNumber]; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 751b994d9..0f577597b 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -625,7 +625,7 @@ static void linphone_iphone_display_status(struct _LinphoneCore *lc, const char - (void)userNotifContinue:(NSTimer *)timer { UNNotificationContent *content = [timer userInfo]; - if (content && [UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { + if (content && [UIApplication sharedApplication].applicationState != UIApplicationStateActive) { LOGI(@"cancelling/presenting user notif"); UNNotificationRequest *req = [UNNotificationRequest requestWithIdentifier:@"call_request" content:content trigger:NULL]; @@ -663,8 +663,6 @@ static void linphone_iphone_display_status(struct _LinphoneCore *lc, const char NSString *address = [FastAddressBook displayNameForAddress:addr]; if (state == LinphoneCallIncomingReceived) { - // TESTING !! - // linphone_call_accept_early_media(call); LinphoneCallLog *callLog = linphone_call_get_call_log(call); NSString *callId = [NSString stringWithUTF8String:linphone_call_log_get_call_id(callLog)]; int index = [(NSNumber *)[_pushDict objectForKey:callId] intValue] - 1; @@ -698,116 +696,118 @@ static void linphone_iphone_display_status(struct _LinphoneCore *lc, const char return; } - if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max && call && - (linphone_core_get_calls_nb(LC) < 2)) { + if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max) { + if (call && (linphone_core_get_calls_nb(LC) < 2)) { #if !TARGET_IPHONE_SIMULATOR - NSString *callId = - [NSString stringWithUTF8String:linphone_call_log_get_call_id(linphone_call_get_call_log(call))]; + NSString *callId = + [NSString stringWithUTF8String:linphone_call_log_get_call_id(linphone_call_get_call_log(call))]; - NSUUID *uuid = [NSUUID UUID]; - [LinphoneManager.instance.providerDelegate.calls setObject:callId forKey:uuid]; - [LinphoneManager.instance.providerDelegate.uuids setObject:uuid forKey:callId]; - BOOL video = FALSE; - video = (([UIApplication sharedApplication].applicationState != UIApplicationStateBackground) && - linphone_core_get_video_policy(LC)->automatically_accept && - linphone_call_params_video_enabled(linphone_call_get_remote_params(call))); - [LinphoneManager.instance.providerDelegate reportIncomingCallwithUUID:uuid handle:address video:video]; + NSUUID *uuid = [NSUUID UUID]; + [LinphoneManager.instance.providerDelegate.calls setObject:callId forKey:uuid]; + [LinphoneManager.instance.providerDelegate.uuids setObject:uuid forKey:callId]; + BOOL video = FALSE; + video = ([UIApplication sharedApplication].applicationState == UIApplicationStateActive && + linphone_core_get_video_policy(LC)->automatically_accept && + linphone_call_params_video_enabled(linphone_call_get_remote_params(call))); + [LinphoneManager.instance.providerDelegate reportIncomingCallwithUUID:uuid handle:address video:video]; #else - [PhoneMainView.instance displayIncomingCall:call]; + [PhoneMainView.instance displayIncomingCall:call]; #endif - } else if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { - // Create a UNNotification - UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; - content.title = NSLocalizedString(@"Incoming call", nil); - content.body = address; - content.sound = [UNNotificationSound soundNamed:@"notes_of_the_optimistic.caf"]; - content.categoryIdentifier = @"call_cat"; - content.userInfo = @{ @"CallId" : callId }; - UNNotificationRequest *req = - [UNNotificationRequest requestWithIdentifier:@"call_request" content:content trigger:NULL]; - [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:req - withCompletionHandler:^(NSError *err){ - }]; - } + } else if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { + // Create a UNNotification + UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; + content.title = NSLocalizedString(@"Incoming call", nil); + content.body = address; + content.sound = [UNNotificationSound soundNamed:@"notes_of_the_optimistic.caf"]; + content.categoryIdentifier = @"call_cat"; + content.userInfo = @{ @"CallId" : callId }; + UNNotificationRequest *req = + [UNNotificationRequest requestWithIdentifier:@"call_request" content:content trigger:NULL]; + [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:req + withCompletionHandler:^(NSError *err){ + }]; + } + } else { + if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { + // if (![LinphoneManager.instance popPushCallID:callId]) { + // case where a remote notification is not already received + // Create a new local notification + if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) { + UIMutableUserNotificationAction *answer = [[UIMutableUserNotificationAction alloc] init]; + answer.identifier = @"answer"; + answer.title = NSLocalizedString(@"Answer", nil); + answer.activationMode = UIUserNotificationActivationModeForeground; + answer.destructive = NO; + answer.authenticationRequired = YES; - if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { - // if (![LinphoneManager.instance popPushCallID:callId]) { - // case where a remote notification is not already received - // Create a new local notification - if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) { - UIMutableUserNotificationAction *answer = [[UIMutableUserNotificationAction alloc] init]; - answer.identifier = @"answer"; - answer.title = NSLocalizedString(@"Answer", nil); - answer.activationMode = UIUserNotificationActivationModeForeground; - answer.destructive = NO; - answer.authenticationRequired = YES; + UIMutableUserNotificationAction *decline = [[UIMutableUserNotificationAction alloc] init]; + decline.identifier = @"decline"; + decline.title = NSLocalizedString(@"Decline", nil); + decline.activationMode = UIUserNotificationActivationModeBackground; + decline.destructive = YES; + decline.authenticationRequired = NO; - UIMutableUserNotificationAction *decline = [[UIMutableUserNotificationAction alloc] init]; - decline.identifier = @"decline"; - decline.title = NSLocalizedString(@"Decline", nil); - decline.activationMode = UIUserNotificationActivationModeBackground; - decline.destructive = YES; - decline.authenticationRequired = NO; + NSArray *callactions = @[ decline, answer ]; - NSArray *callactions = @[ decline, answer ]; + UIMutableUserNotificationCategory *callcat = [[UIMutableUserNotificationCategory alloc] init]; + callcat.identifier = @"incoming_call"; + [callcat setActions:callactions forContext:UIUserNotificationActionContextDefault]; + [callcat setActions:callactions forContext:UIUserNotificationActionContextMinimal]; - UIMutableUserNotificationCategory *callcat = [[UIMutableUserNotificationCategory alloc] init]; - callcat.identifier = @"incoming_call"; - [callcat setActions:callactions forContext:UIUserNotificationActionContextDefault]; - [callcat setActions:callactions forContext:UIUserNotificationActionContextMinimal]; + NSSet *categories = [NSSet setWithObjects:callcat, nil]; - NSSet *categories = [NSSet setWithObjects:callcat, nil]; + UIUserNotificationSettings *set = [UIUserNotificationSettings + settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | + UIUserNotificationTypeSound) + categories:categories]; + [[UIApplication sharedApplication] registerUserNotificationSettings:set]; + data->notification = [[UILocalNotification alloc] init]; + if (data->notification) { + // iOS8 doesn't need the timer trick for the local notification. + data->notification.category = @"incoming_call"; + if ([[UIDevice currentDevice].systemVersion floatValue] >= 8 && + [self lpConfigBoolForKey:@"repeat_call_notification"] == NO) { + NSString *ring = ([LinphoneManager bundleFile:[self lpConfigStringForKey:@"local_ring" + inSection:@"sound"] + .lastPathComponent] + ?: [LinphoneManager bundleFile:@"notes_of_the_optimistic.caf"]) + .lastPathComponent; + data->notification.soundName = ring; + } else { + data->notification.soundName = @"shortring.caf"; + data->timer = [NSTimer scheduledTimerWithTimeInterval:5 + target:self + selector:@selector(localNotifContinue:) + userInfo:data->notification + repeats:TRUE]; + } - UIUserNotificationSettings *set = [UIUserNotificationSettings - settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | - UIUserNotificationTypeSound) - categories:categories]; - [[UIApplication sharedApplication] registerUserNotificationSettings:set]; - data->notification = [[UILocalNotification alloc] init]; - if (data->notification) { - // iOS8 doesn't need the timer trick for the local notification. - data->notification.category = @"incoming_call"; - if ([[UIDevice currentDevice].systemVersion floatValue] >= 8 && - [self lpConfigBoolForKey:@"repeat_call_notification"] == NO) { - NSString *ring = - ([LinphoneManager bundleFile:[self lpConfigStringForKey:@"local_ring" inSection:@"sound"].lastPathComponent] - ?: [LinphoneManager bundleFile:@"notes_of_the_optimistic.caf"]) - .lastPathComponent; - data->notification.soundName = ring; - } else { - data->notification.soundName = @"shortring.caf"; - data->timer = [NSTimer scheduledTimerWithTimeInterval:5 - target:self - selector:@selector(localNotifContinue:) - userInfo:data->notification - repeats:TRUE]; - } + data->notification.repeatInterval = 0; - data->notification.repeatInterval = 0; + data->notification.alertBody = + [NSString stringWithFormat:NSLocalizedString(@"IC_MSG", nil), address]; + // data->notification.alertAction = NSLocalizedString(@"Answer", nil); + data->notification.userInfo = @{ @"callId" : callId, @"timer" : [NSNumber numberWithInt:1] }; + data->notification.applicationIconBadgeNumber = 1; + UIApplication *app = [UIApplication sharedApplication]; + LOGI([app currentUserNotificationSettings].description); + [app presentLocalNotificationNow:data->notification]; - data->notification.alertBody = - [NSString stringWithFormat:NSLocalizedString(@"IC_MSG", nil), address]; - //data->notification.alertAction = NSLocalizedString(@"Answer", nil); - data->notification.userInfo = @{ @"callId" : callId, @"timer" : [NSNumber numberWithInt:1] }; - data->notification.applicationIconBadgeNumber = 1; - UIApplication *app = [UIApplication sharedApplication]; - LOGI([app currentUserNotificationSettings].description); - [app presentLocalNotificationNow:data->notification]; + if (!incallBgTask) { + incallBgTask = + [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ + LOGW(@"Call cannot ring any more, too late"); + [[UIApplication sharedApplication] endBackgroundTask:incallBgTask]; + incallBgTask = 0; + }]; - if (!incallBgTask) { - incallBgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ - LOGW(@"Call cannot ring any more, too late"); - [[UIApplication sharedApplication] endBackgroundTask:incallBgTask]; - incallBgTask = 0; - }]; - - if (data->timer) { - [[NSRunLoop currentRunLoop] addTimer:data->timer forMode:NSRunLoopCommonModes]; + if (data->timer) { + [[NSRunLoop currentRunLoop] addTimer:data->timer forMode:NSRunLoopCommonModes]; + } } } } - } - + } } } @@ -835,7 +835,7 @@ static void linphone_iphone_display_status(struct _LinphoneCore *lc, const char } if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max) { - if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { + if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { if (data->timer) { [data->timer invalidate]; data->timer = nil; @@ -1122,7 +1122,7 @@ static void linphone_iphone_popup_password_request(LinphoneCore *lc, const char // dont pop up if we are in background, in any case we will refresh registers when entering // the application again - if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) { + if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateActive) { return; } @@ -1208,7 +1208,7 @@ static void linphone_iphone_popup_password_request(LinphoneCore *lc, const char } if (linphone_chat_message_is_file_transfer(msg) || linphone_chat_message_is_text(msg)) { - if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground || + if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive || ((PhoneMainView.instance.currentView != ChatsListView.compositeViewDescription) && ((PhoneMainView.instance.currentView != ChatConversationView.compositeViewDescription))) || (PhoneMainView.instance.currentView == ChatConversationView.compositeViewDescription && @@ -1382,7 +1382,7 @@ static void linphone_iphone_message_received_unable_decrypt(LinphoneCore *lc, Li strAddr]; NSString *action = NSLocalizedString(@"Call", nil); - if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { + if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max) { UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; content.title = title; @@ -1501,7 +1501,7 @@ static void linphone_iphone_call_encryption_changed(LinphoneCore *lc, LinphoneCa @"Please call this contact and verify his ZRTP key before sending your messages.", nil); - if ([UIApplication sharedApplication].applicationState != UIApplicationStateBackground) { + if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) { UIAlertController *errView = [UIAlertController alertControllerWithTitle:title message:body preferredStyle:UIAlertControllerStyleAlert]; @@ -2249,7 +2249,7 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { [[UIApplication sharedApplication] endBackgroundTask:pushBgTask]; pushBgTask = 0; pushBgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ - if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { + if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { if (msg) { LOGW(@"Incomming message couldn't be received"); UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; diff --git a/Classes/LinphoneUI/StatusBarView.m b/Classes/LinphoneUI/StatusBarView.m index 43db8ee5e..797e6d116 100644 --- a/Classes/LinphoneUI/StatusBarView.m +++ b/Classes/LinphoneUI/StatusBarView.m @@ -335,7 +335,7 @@ nil), myCode, correspondantCode]; - if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground && + if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max) { UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; content.title = NSLocalizedString(@"ZRTP verification", nil); diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.m b/Classes/LinphoneUI/UIChatBubbleTextCell.m index 326441ad7..703e4c6ed 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.m +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.m @@ -150,8 +150,7 @@ [_messageText setAccessibilityLabel:@"Outgoing message"]; } else { [_messageText setAccessibilityLabel:@"Incoming message"]; - if (!([UIApplication sharedApplication].applicationState == UIApplicationStateBackground || - [UIApplication sharedApplication].applicationState == UIApplicationStateInactive)) { + if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) { VIEW(ChatConversationView).markAsRead; } } diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index aa873f26a..e4340da5d 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -274,7 +274,7 @@ static RootViewManager *rootViewManagerInstance = nil; linphone_chat_room_get_peer_address(view.chatRoom))) return; - if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) + if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) return; LinphoneManager *lm = LinphoneManager.instance; @@ -287,7 +287,7 @@ static RootViewManager *rootViewManagerInstance = nil; - (void)registrationUpdate:(NSNotification *)notif { LinphoneRegistrationState state = [[notif.userInfo objectForKey:@"state"] intValue]; if (state == LinphoneRegistrationFailed && ![currentView equal:AssistantView.compositeViewDescription] && - [UIApplication sharedApplication].applicationState != UIApplicationStateBackground) { + [UIApplication sharedApplication].applicationState == UIApplicationStateActive) { UIAlertController *errView = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Registration failure", nil) message:[notif.userInfo objectForKey:@"message"] preferredStyle:UIAlertControllerStyleAlert]; @@ -732,7 +732,7 @@ static RootViewManager *rootViewManagerInstance = nil; LinphoneCallLog *callLog = linphone_call_get_call_log(call); NSString *callId = [NSString stringWithUTF8String:linphone_call_log_get_call_id(callLog)]; - if ([UIApplication sharedApplication].applicationState != UIApplicationStateBackground) { + if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) { LinphoneManager *lm = LinphoneManager.instance; BOOL callIDFromPush = [lm popPushCallID:callId]; BOOL autoAnswer = [lm lpConfigBoolForKey:@"autoanswer_notif_preference"]; diff --git a/Classes/ProviderDelegate.m b/Classes/ProviderDelegate.m index e7936cd3e..83811eecb 100644 --- a/Classes/ProviderDelegate.m +++ b/Classes/ProviderDelegate.m @@ -88,7 +88,7 @@ NSString *callID = [self.calls objectForKey:uuid]; // first, make sure this callid is not already involved in a call LinphoneCall *call = [LinphoneManager.instance callByCallId:callID]; if (call != NULL) { - BOOL video = (!([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) && + BOOL video = ([UIApplication sharedApplication].applicationState == UIApplicationStateActive && linphone_core_get_video_policy(LC)->automatically_accept && linphone_call_params_video_enabled(linphone_call_get_remote_params((LinphoneCall *)call))); self.pendingCall = call; @@ -129,12 +129,14 @@ } else { NSUUID *uuid = action.callUUID; NSString *callID = [self.calls objectForKey:uuid]; - LinphoneCall *call = [LinphoneManager.instance callByCallId:callID]; - if (call) { - linphone_call_terminate((LinphoneCall *)call); + if (callID) { + LinphoneCall *call = [LinphoneManager.instance callByCallId:callID]; + if (call) { + linphone_call_terminate((LinphoneCall *)call); + } + [self.uuids removeObjectForKey:callID]; + [self.calls removeObjectForKey:uuid]; } - [self.uuids removeObjectForKey:callID]; - [self.calls removeObjectForKey:uuid]; } }