diff --git a/Classes/LinphoneAppDelegate.h b/Classes/LinphoneAppDelegate.h index 1e2af5e9a..223b3d390 100644 --- a/Classes/LinphoneAppDelegate.h +++ b/Classes/LinphoneAppDelegate.h @@ -26,13 +26,12 @@ @interface LinphoneAppDelegate : NSObject { @private UIBackgroundTaskIdentifier bgStartId; - BOOL started; + BOOL startedInBackground; int savedMaxCall; } - (void)processRemoteNotification:(NSDictionary*)userInfo; -@property (assign) BOOL started; @property (nonatomic, retain) UIAlertView *waitingIndicator; @property (nonatomic, retain) NSString *configURL; @property (nonatomic, strong) UIWindow* window; diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 222f5a25f..9a84cf260 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -32,7 +32,7 @@ @implementation LinphoneAppDelegate -@synthesize started,configURL; +@synthesize configURL; @synthesize window; #pragma mark - Lifecycle Functions @@ -40,7 +40,7 @@ - (id)init { self = [super init]; if(self != nil) { - self->started = FALSE; + self->startedInBackground = FALSE; } return self; } @@ -89,6 +89,11 @@ [LinphoneLogger logc:LinphoneLoggerLog format:"applicationDidBecomeActive"]; [self startApplication]; + if( startedInBackground ){ + startedInBackground = FALSE; + [[PhoneMainView instance] startUp]; + [[PhoneMainView instance] updateStatusBar:nil]; + } LinphoneManager* instance = [LinphoneManager instance]; [instance becomeActive]; @@ -172,6 +177,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UIApplication* app= [UIApplication sharedApplication]; + UIApplicationState state = app.applicationState; if( [app respondsToSelector:@selector(registerUserNotificationSettings:)] ){ /* iOS8 notifications can be actioned! Awesome: */ @@ -185,14 +191,14 @@ NSUInteger notifTypes = UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeNewsstandContentAvailability; [app registerForRemoteNotificationTypes:notifTypes]; } - LinphoneManager* instance = [LinphoneManager instance]; BOOL background_mode = [instance lpConfigBoolForKey:@"backgroundmode_preference"]; BOOL start_at_boot = [instance lpConfigBoolForKey:@"start_at_boot_preference"]; + if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] - && [UIApplication sharedApplication].applicationState == UIApplicationStateBackground) + && state == UIApplicationStateBackground) { // we've been woken up directly to background; if( !start_at_boot || !background_mode ) { @@ -207,14 +213,25 @@ [LinphoneLogger log:LinphoneLoggerWarning format:@"Background task for application launching expired."]; [[UIApplication sharedApplication] endBackgroundTask:bgStartId]; }]; + [self startApplication]; + // initialize UI + [self.window makeKeyAndVisible]; + [RootViewManager setupWithPortrait:(PhoneMainView*)self.window.rootViewController]; + if( state == UIApplicationStateBackground ){ + startedInBackground = TRUE; + } else { + [[PhoneMainView instance] startUp]; + [[PhoneMainView instance] updateStatusBar:nil]; + } + + NSDictionary *remoteNotif =[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if (remoteNotif){ [LinphoneLogger log:LinphoneLoggerLog format:@"PushNotification from launch received."]; [self processRemoteNotification:remoteNotif]; } if (bgStartId!=UIBackgroundTaskInvalid) [[UIApplication sharedApplication] endBackgroundTask:bgStartId]; - [[PhoneMainView instance] updateStatusBar:nil]; return YES; } @@ -224,11 +241,6 @@ if(![LinphoneManager isLcReady]) { [[LinphoneManager instance] startLibLinphone]; } - if([LinphoneManager isLcReady] && !started) { - started = TRUE; - [self.window makeKeyAndVisible]; - [[PhoneMainView instance] startUp]; - } } - (void)applicationWillTerminate:(UIApplication *)application { diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index 49374cfbc..18d98df25 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -431,26 +431,31 @@ static RootViewManager* rootViewManagerInstance = nil; } - (void)startUp { - - if( linphone_core_get_global_state([LinphoneManager getLc]) != LinphoneGlobalOn ){ - [self changeCurrentView: [DialerViewController compositeViewDescription]]; - } else if ([[LinphoneManager instance] lpConfigBoolForKey:@"enable_first_login_view_preference"] == true) { - // Change to fist login view - [self changeCurrentView: [FirstLoginViewController compositeViewDescription]]; - } else { - // Change to default view - const MSList *list = linphone_core_get_proxy_config_list([LinphoneManager getLc]); - if(list != NULL || ([[LinphoneManager instance] lpConfigBoolForKey:@"hide_wizard_preference"] == true)) { + LinphoneCore* core = nil; + @try { + core = [LinphoneManager getLc]; + if( linphone_core_get_global_state(core) != LinphoneGlobalOn ){ [self changeCurrentView: [DialerViewController compositeViewDescription]]; + } else if ([[LinphoneManager instance] lpConfigBoolForKey:@"enable_first_login_view_preference"] == true) { + // Change to fist login view + [self changeCurrentView: [FirstLoginViewController compositeViewDescription]]; } else { - WizardViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[WizardViewController compositeViewDescription]], WizardViewController); - if(controller != nil) { - [controller reset]; + // Change to default view + const MSList *list = linphone_core_get_proxy_config_list(core); + if(list != NULL || ([[LinphoneManager instance] lpConfigBoolForKey:@"hide_wizard_preference"] == true)) { + [self changeCurrentView: [DialerViewController compositeViewDescription]]; + } else { + WizardViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[WizardViewController compositeViewDescription]], WizardViewController); + if(controller != nil) { + [controller reset]; + } } } + [self updateApplicationBadgeNumber]; // Update Badge at startup + } + @catch (NSException *exception) { + // we'll wait until the app transitions correctly } - - [self updateApplicationBadgeNumber]; // Update Badge at startup } - (void)updateApplicationBadgeNumber {