diff --git a/Classes/LinphoneAppDelegate.h b/Classes/LinphoneAppDelegate.h index 8b0076e3c..6ab39badf 100644 --- a/Classes/LinphoneAppDelegate.h +++ b/Classes/LinphoneAppDelegate.h @@ -32,12 +32,14 @@ UIWindow *window; BOOL started; int savedMaxCall; - } - (void)processRemoteNotification:(NSDictionary*)userInfo; @property (assign) BOOL started; +@property (nonatomic, retain) UIAlertView *waitingIndicator; +@property (nonatomic, retain) NSString *configURL; + @end diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 6226d7bff..f434c4510 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -36,7 +36,7 @@ @implementation LinphoneAppDelegate -@synthesize started; +@synthesize started,configURL; #pragma mark - Lifecycle Functions @@ -91,31 +91,31 @@ - (void)applicationDidBecomeActive:(UIApplication *)application { [LinphoneLogger logc:LinphoneLoggerLog format:"applicationDidBecomeActive"]; - + [self startApplication]; LinphoneManager* instance = [LinphoneManager instance]; - - [instance becomeActive]; + + [instance becomeActive]; LinphoneCore* lc = [LinphoneManager getLc]; LinphoneCall* call = linphone_core_get_current_call(lc); - - if (call){ - if (call == instance->currentCallContextBeforeGoingBackground.call) { - const LinphoneCallParams* params = linphone_call_get_current_params(call); - if (linphone_call_params_video_enabled(params)) { - linphone_call_enable_camera( - call, - instance->currentCallContextBeforeGoingBackground.cameraIsEnabled); - } - instance->currentCallContextBeforeGoingBackground.call = 0; - } else if ( linphone_call_get_state(call) == LinphoneCallIncomingReceived ) { + + if (call){ + if (call == instance->currentCallContextBeforeGoingBackground.call) { + const LinphoneCallParams* params = linphone_call_get_current_params(call); + if (linphone_call_params_video_enabled(params)) { + linphone_call_enable_camera( + call, + instance->currentCallContextBeforeGoingBackground.cameraIsEnabled); + } + instance->currentCallContextBeforeGoingBackground.call = 0; + } else if ( linphone_call_get_state(call) == LinphoneCallIncomingReceived ) { [[PhoneMainView instance ] displayIncomingCall:call]; // in this case, the ringing sound comes from the notification. // To stop it we have to do the iOS7 ring fix... [self fixRing]; } - } + } } @@ -177,19 +177,31 @@ } } - - (void)applicationWillTerminate:(UIApplication *)application { [LinphoneLogger log:LinphoneLoggerLog format:@"Application Will Terminate"]; } - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { - [self startApplication]; - if([LinphoneManager isLcReady]) { - if([[url scheme] isEqualToString:@"sip"]) { - // Go to Dialer view - DialerViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[DialerViewController compositeViewDescription]], DialerViewController); - if(controller != nil) { - [controller setAddress:[url absoluteString]]; + NSString *scheme = [[url scheme] lowercaseString]; + if ([scheme isEqualToString:@"linphone-config-http"] || [scheme isEqualToString:@"linphone-config-https"]) { + configURL = [[NSString alloc] initWithString:[[url absoluteString] stringByReplacingOccurrencesOfString:@"linphone-config-" withString:@""]]; + UIAlertView* confirmation = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Remote configuration",nil) + message:NSLocalizedString(@"This operation will load a remote configuration. Continue ?",nil) + delegate:self + cancelButtonTitle:NSLocalizedString(@"No",nil) + otherButtonTitles:NSLocalizedString(@"Yes",nil),nil]; + confirmation.tag = 1; + [confirmation show]; + [confirmation release]; + } else { + [self startApplication]; + if([LinphoneManager isLcReady]) { + if([[url scheme] isEqualToString:@"sip"]) { + // Go to Dialer view + DialerViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[DialerViewController compositeViewDescription]], DialerViewController); + if(controller != nil) { + [controller setAddress:[url absoluteString]]; + } } } } @@ -300,4 +312,95 @@ [[LinphoneManager instance] setPushNotificationToken:nil]; } +#pragma mark - Remote configuration Functions (URL Handler) + + +- (void)ConfigurationStateUpdateEvent: (NSNotification*) notif { + LinphoneConfiguringState state = [[notif.userInfo objectForKey: @"state"] intValue]; + if (state == LinphoneConfiguringSuccessful) { + [[NSNotificationCenter defaultCenter] removeObserver:self + name:kLinphoneConfiguringStateUpdate + object:nil]; + [_waitingIndicator dismissWithClickedButtonIndex:0 animated:true]; + + UIAlertView* error = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Success",nil) + message:NSLocalizedString(@"Remote configuration successfully fetched and applied.",nil) + delegate:nil + cancelButtonTitle:NSLocalizedString(@"OK",nil) + otherButtonTitles:nil]; + [error show]; + [error release]; + [[PhoneMainView instance] startUp]; + } + if (state == LinphoneConfiguringFailed) { + [[NSNotificationCenter defaultCenter] removeObserver:self + name:kLinphoneConfiguringStateUpdate + object:nil]; + [_waitingIndicator dismissWithClickedButtonIndex:0 animated:true]; + UIAlertView* error = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Failure",nil) + message:NSLocalizedString(@"Failed configuring from the specified URL." ,nil) + delegate:nil + cancelButtonTitle:NSLocalizedString(@"OK",nil) + otherButtonTitles:nil]; + [error show]; + [error release]; + + } +} + + +- (void) showWaitingIndicator { + _waitingIndicator = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Fetching remote configuration...",nil) message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:nil]; + UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 60, 30, 30)]; + progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge; + if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){ + [_waitingIndicator setValue:progress forKey:@"accessoryView"]; + [progress setColor:[UIColor blackColor]]; + } else { + [_waitingIndicator addSubview:progress]; + } + [progress startAnimating]; + [_waitingIndicator show]; + +} + + +- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex +{ + if ((alertView.tag == 1) && (buttonIndex==1)) { + [self showWaitingIndicator]; + if([LinphoneManager isLcReady]) { + [self attemptRemoteConfiguration]; + } else { + [[LinphoneManager instance] startLibLinphone]; + [self performSelector:@selector(attemptRemoteConfiguration) withObject:NULL afterDelay:5.0]; + } + } + +} + +- (void)attemptRemoteConfiguration { + + if ([LinphoneManager isLcReady]) { + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(ConfigurationStateUpdateEvent:) + name:kLinphoneConfiguringStateUpdate + object:nil]; + linphone_core_set_provisioning_uri([LinphoneManager getLc] , [configURL UTF8String]); + [[LinphoneManager instance] destroyLibLinphone]; + [[LinphoneManager instance] startLibLinphone]; + } else { + [_waitingIndicator dismissWithClickedButtonIndex:0 animated:true]; + UIAlertView* error = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Failure",nil) + message:NSLocalizedString(@"Linphone is not ready.",nil) + delegate:nil + cancelButtonTitle:NSLocalizedString(@"OK",nil) + otherButtonTitles:nil]; + [error show]; + [error release]; + + } +} + + @end diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index c289ae2d5..fcb9b1c98 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -1016,9 +1016,10 @@ static LinphoneCoreVTable linphonec_vtable = { } +static BOOL libStarted = FALSE; + - (void)startLibLinphone { - static BOOL libStarted = FALSE; if ( libStarted ) { [LinphoneLogger logc:LinphoneLoggerError format:"Liblinphone is already initialized!"]; return; @@ -1143,6 +1144,7 @@ static LinphoneCoreVTable linphonec_vtable = { proxyReachability=nil; } + libStarted = FALSE; } - (void) resetLinphoneCore { diff --git a/Classes/LinphoneUI/UIStateBar.m b/Classes/LinphoneUI/UIStateBar.m index 99a8835fb..787f07279 100644 --- a/Classes/LinphoneUI/UIStateBar.m +++ b/Classes/LinphoneUI/UIStateBar.m @@ -130,7 +130,7 @@ NSTimer *callSecurityTimer; } - (void) globalStateUpdate:(NSNotification*) notif { - [self registrationUpdate:notif]; + if ([LinphoneManager isLcReady]) [self registrationUpdate:notif]; } diff --git a/linphone-Info.plist b/linphone-Info.plist index b776fd5d1..8c7ffad31 100644 --- a/linphone-Info.plist +++ b/linphone-Info.plist @@ -74,6 +74,30 @@ sip + + CFBundleTypeRole + Viewer + CFBundleURLIconFile + linphone_icon_72@2x + CFBundleURLName + org.linphone.phone + CFBundleURLSchemes + + linphone-config-http + + + + CFBundleTypeRole + Viewer + CFBundleURLIconFile + linphone_icon_72@2x + CFBundleURLName + org.linphone.phone + CFBundleURLSchemes + + linphone-config-https + + CFBundleVersion 2.1.2