iOS: fallback to use [UIScreen mainScreen] when [UIScreen screens] fail

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ø <tor.arne.vestbo@digia.com>
This commit is contained in:
Richard Moe Gustavsen 2014-11-24 11:21:07 +01:00 committed by Jani Heikkinen
parent 89867f86fc
commit 503b9c3181

View File

@ -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