From 9cc1a2c9f2ed54d47e2876dfe894b4f4eb7f8af6 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Tue, 5 Apr 2016 14:06:37 +0200 Subject: [PATCH] UICompositeView.m: try to fix some crash in rotation handling --- Classes/LinphoneUI/UICompositeView.m | 27 +++++++++++++++---------- Classes/LinphoneUI/UIRoundedImageView.m | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Classes/LinphoneUI/UICompositeView.m b/Classes/LinphoneUI/UICompositeView.m index 3e2d9ad77..8efa426db 100644 --- a/Classes/LinphoneUI/UICompositeView.m +++ b/Classes/LinphoneUI/UICompositeView.m @@ -153,6 +153,7 @@ - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; + [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [self.mainViewController viewWillAppear:animated]; [self.detailsViewController viewWillAppear:animated]; [self.tabBarViewController viewWillAppear:animated]; @@ -162,7 +163,6 @@ selector:@selector(orientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil]; - [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; } - (void)viewDidAppear:(BOOL)animated { @@ -175,25 +175,23 @@ } - (void)viewWillDisappear:(BOOL)animated { - [super viewWillDisappear:animated]; [self.mainViewController viewWillDisappear:animated]; [self.detailsViewController viewWillDisappear:animated]; [self.tabBarViewController viewWillDisappear:animated]; [self.statusBarViewController viewWillDisappear:animated]; [self.sideMenuViewController viewWillDisappear:animated]; - - [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; - [NSNotificationCenter.defaultCenter removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]; + [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; + [super viewWillDisappear:animated]; } - (void)viewDidDisappear:(BOOL)animated { - [super viewDidDisappear:animated]; [self.mainViewController viewDidDisappear:animated]; [self.detailsViewController viewDidDisappear:animated]; [self.tabBarViewController viewDidDisappear:animated]; [self.statusBarViewController viewDidDisappear:animated]; [self.sideMenuViewController viewDidDisappear:animated]; + [super viewDidDisappear:animated]; } #pragma mark - Rotation messages @@ -239,11 +237,18 @@ #pragma mark - Event Functions - (void)orientationDidChange:(NSNotification *)notif { - // Update rotation - UIInterfaceOrientation correctOrientation = - [self getCorrectInterfaceOrientation:[[UIDevice currentDevice] orientation]]; - if (currentOrientation != correctOrientation) { - [UICompositeView setOrientation:correctOrientation animated:currentOrientation != UIDeviceOrientationUnknown]; + @try { + // Update rotation + UIInterfaceOrientation correctOrientation = + [self getCorrectInterfaceOrientation:[[UIDevice currentDevice] orientation]]; + if (currentOrientation != correctOrientation) { + [UICompositeView setOrientation:correctOrientation + animated:currentOrientation != UIDeviceOrientationUnknown]; + } + } @catch (NSException *exception) { + // There are some crashes reports from iTunes connect because Linphone core is + // not ready yet - whatever the reason is, we can safely ignore the exception + LOGE(@"Exception: %@, ignoring", exception); } } diff --git a/Classes/LinphoneUI/UIRoundedImageView.m b/Classes/LinphoneUI/UIRoundedImageView.m index 2b75d4eee..46f52857f 100644 --- a/Classes/LinphoneUI/UIRoundedImageView.m +++ b/Classes/LinphoneUI/UIRoundedImageView.m @@ -25,7 +25,7 @@ INIT_WITH_COMMON_CF { [self setRoundRadius]; [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(orientationDidChange:) - name:@"UIDeviceOrientationDidChangeNotification" + name:UIDeviceOrientationDidChangeNotification object:nil]; return self; }