From 19acd2981b2a8ef9ad2c4373916dcd1854b5a288 Mon Sep 17 00:00:00 2001 From: Danmei Chen Date: Mon, 28 Jan 2019 15:36:07 +0100 Subject: [PATCH] fix crash of creating chatroom when no network --- Classes/FirstLoginView.m | 13 +------------ Classes/LinphoneManager.m | 11 +---------- Classes/PhoneMainView.m | 7 ++++++- Classes/Utils/Utils.h | 1 + Classes/Utils/Utils.m | 17 +++++++++++++++++ 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/Classes/FirstLoginView.m b/Classes/FirstLoginView.m index d4eea95f5..3d6358c3a 100644 --- a/Classes/FirstLoginView.m +++ b/Classes/FirstLoginView.m @@ -200,18 +200,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)onLoginClick:(id)sender { if (!linphone_core_is_network_reachable(LC)) { - UIAlertController *errView = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Network Error", nil) - message:NSLocalizedString(@"There is no network connection available, enable " - @"WIFI or WWAN prior to configure an account", - nil) - preferredStyle:UIAlertControllerStyleAlert]; - - UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) {}]; - - [errView addAction:defaultAction]; - [self presentViewController:errView animated:YES completion:nil]; + [PhoneMainView.instance presentViewController:[LinphoneUtils networkErrorView] animated:YES completion:nil]; return; } diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 52ee5690c..e9c99228a 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -2676,16 +2676,7 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { - (void)call:(const LinphoneAddress *)iaddr { // First verify that network is available, abort otherwise. if (!linphone_core_is_network_reachable(theLinphoneCore)) { - UIAlertController *errView = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Network Error", nil) - message:NSLocalizedString(@"There is no network connection available, enable WIFI or WWAN prior to place a call", nil) - preferredStyle:UIAlertControllerStyleAlert]; - - UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) {}]; - - [errView addAction:defaultAction]; - [PhoneMainView.instance presentViewController:errView animated:YES completion:nil]; + [PhoneMainView.instance presentViewController:[LinphoneUtils networkErrorView] animated:YES completion:nil]; return; } diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index 1a8de7336..5caa8790b 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -878,7 +878,12 @@ static RootViewManager *rootViewManagerInstance = nil; [self changeCurrentView:ChatsListView.compositeViewDescription]; return; } - + + if (!linphone_core_is_network_reachable(LC)) { + [PhoneMainView.instance presentViewController:[LinphoneUtils networkErrorView] animated:YES completion:nil]; + return; + } + const LinphoneAddress *local = linphone_proxy_config_get_contact(linphone_core_get_default_proxy_config(LC)); LinphoneChatRoom *room = linphone_core_find_one_to_one_chat_room_2(LC, local, remoteAddress, isEncrypted); if (!room) { diff --git a/Classes/Utils/Utils.h b/Classes/Utils/Utils.h index b3cca7947..ec0b87f9e 100644 --- a/Classes/Utils/Utils.h +++ b/Classes/Utils/Utils.h @@ -33,6 +33,7 @@ + (NSString *)deviceModelIdentifier; + (LinphoneAddress *)normalizeSipOrPhoneAddress:(NSString *)addr; ++ (UIAlertController *)networkErrorView; typedef enum { LinphoneDateHistoryList, diff --git a/Classes/Utils/Utils.m b/Classes/Utils/Utils.m index 97d678319..439536356 100644 --- a/Classes/Utils/Utils.m +++ b/Classes/Utils/Utils.m @@ -531,6 +531,23 @@ return res; } ++ (UIAlertController *)networkErrorView { + UIAlertController *errView = + [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Network Error", nil) + message:NSLocalizedString(@"There is no network connection available, " + @"enable WIFI or WWAN prior to place a call", + nil) + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *action){ + }]; + + [errView addAction:defaultAction]; + return errView; +} + @end @implementation NSNumber (HumanReadableSize)