From 503b9c318164122b0111f6d0d9d3b680c8ca016f Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Mon, 24 Nov 2014 11:21:07 +0100 Subject: iOS: fallback to use [UIScreen mainScreen] when [UIScreen screens] fail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On iOS 7.1 [UIScreen screens] sometimes (and against documentation) returns an empty array, which will lead to a crash. This patch will add a fallback path that uses [UIScreen mainScreen] instead when the screen count is 0. Task-number: QTBUG-42345 Change-Id: Ie72578ff7ecd0c8fbc971fafea45047bf1347cd9 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qiosintegration.mm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/ios/qiosintegration.mm b/src/plugins/platforms/ios/qiosintegration.mm index 9a722ead37..461f160892 100644 --- a/src/plugins/platforms/ios/qiosintegration.mm +++ b/src/plugins/platforms/ios/qiosintegration.mm @@ -88,7 +88,13 @@ QIOSIntegration::QIOSIntegration() // Set current directory to app bundle folder QDir::setCurrent(QString::fromUtf8([[[NSBundle mainBundle] bundlePath] UTF8String])); - for (UIScreen *screen in [UIScreen screens]) + NSMutableArray *screens = [[[UIScreen screens] mutableCopy] autorelease]; + if (![screens containsObject:[UIScreen mainScreen]]) { + // Fallback for iOS 7.1 (QTBUG-42345) + [screens insertObject:[UIScreen mainScreen] atIndex:0]; + } + + for (UIScreen *screen in screens) addScreen(new QIOSScreen(screen)); // Depends on a primary screen being present -- cgit v1.2.3