From 491c4dad83ceb7ed7a87557e26fe05f0f57524b9 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Fri, 22 Jan 2016 16:33:39 +0100 Subject: [PATCH] dialer: add self-destruct hack --- Classes/DialerView.m | 15 +++++++++++++++ Classes/LinphoneManager.m | 17 ++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Classes/DialerView.m b/Classes/DialerView.m index cc3fb3028..45fa153ae 100644 --- a/Classes/DialerView.m +++ b/Classes/DialerView.m @@ -271,6 +271,21 @@ static UICompositeViewDescription *compositeDescription = nil; [Log enableLogs:newDebugLevel]; }]; + [alertView addButtonWithTitle:NSLocalizedString(@"Remove account(s) and self destruct", nil) + block:^{ + linphone_core_clear_proxy_config([LinphoneManager getLc]); + linphone_core_clear_all_auth_info([LinphoneManager getLc]); + [LinphoneManager.instance destroyLinphoneCore]; + if ([NSFileManager.defaultManager + isDeletableFileAtPath:[LinphoneManager documentFile:@"linphonerc"]] == YES) { + [NSFileManager.defaultManager + removeItemAtPath:[LinphoneManager documentFile:@"linphonerc"] + error:nil]; + } + [LinphoneManager instanceRelease]; + [UIApplication sharedApplication].keyWindow.rootViewController = nil; + }]; + [alertView show]; return true; } diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index e6a5626e2..489891d47 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -781,10 +781,14 @@ static void linphone_iphone_global_state_changed(LinphoneCore *lc, LinphoneGloba dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:state], @"state", [NSString stringWithUTF8String:message ? message : ""], @"message", nil]; - // dispatch the notification asynchronously - dispatch_async(dispatch_get_main_queue(), ^(void) { - [NSNotificationCenter.defaultCenter postNotificationName:kLinphoneGlobalStateUpdate object:self userInfo:dict]; - }); + if (state == LinphoneGlobalShutdown) { + theLinphoneCore = nil; + } else { + // dispatch the notification asynchronously + dispatch_async(dispatch_get_main_queue(), ^(void) { + [NSNotificationCenter.defaultCenter postNotificationName:kLinphoneGlobalStateUpdate object:self userInfo:dict]; + }); + } } - (void)globalStateChangedNotificationHandler:(NSNotification *)notif { @@ -1491,8 +1495,6 @@ static BOOL libStarted = FALSE; // just in case [self removeCTCallCenterCb]; - [NSNotificationCenter.defaultCenter removeObserver:self]; - if (theLinphoneCore != nil) { // just in case application terminate before linphone core initialization for (FileTransferDelegate *ftd in _fileTransferDelegates) { @@ -1518,6 +1520,7 @@ static BOOL libStarted = FALSE; proxyReachability = nil; } libStarted = FALSE; + [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)resetLinphoneCore { @@ -2060,7 +2063,7 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { } + (BOOL)copyFile:(NSString *)src destination:(NSString *)dst override:(BOOL)override { - NSFileManager *fileManager = [NSFileManager defaultManager]; + NSFileManager *fileManager = NSFileManager.defaultManager; NSError *error = nil; if ([fileManager fileExistsAtPath:src] == NO) { LOGE(@"Can't find \"%@\": %@", src, [error localizedDescription]);