From fb72f21cdcd2c7eb494694811efc0ab948a6ead3 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Fri, 3 Feb 2017 12:25:05 -0800 Subject: [PATCH] Improved detection of unsupported iOS devices (#7857) * Detects iPad 2 and iPad Retina as unsupported devices. * Simplifies blacklisting logic. * Minor improvements to error messages. * Added unit tests. --- .../flutter_tools/lib/src/ios/simulators.dart | 33 +++++++++--------- .../test/src/ios/simulators_test.dart | 34 +++++++++++++++++++ 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/packages/flutter_tools/lib/src/ios/simulators.dart b/packages/flutter_tools/lib/src/ios/simulators.dart index d07479a950..208617bed3 100644 --- a/packages/flutter_tools/lib/src/ios/simulators.dart +++ b/packages/flutter_tools/lib/src/ios/simulators.dart @@ -369,9 +369,8 @@ class IOSSimulator extends Device { // We do not support WatchOS or tvOS devices. RegExp blacklist = new RegExp(r'Apple (TV|Watch)', caseSensitive: false); - if (blacklist.hasMatch(name)) { - _supportMessage = 'Flutter does not support either the Apple TV or Watch. Choose an iPhone 5s or above.'; + _supportMessage = 'Flutter does not support Apple TV or Apple Watch. Select an iPhone 5s or above.'; return false; } @@ -380,23 +379,23 @@ class IOSSimulator extends Device { // targeted applications cannot be run (even though the Flutter // runner on the simulator is completely different). - RegExp versionExp = new RegExp(r'iPhone ([0-9])+'); - Match match = versionExp.firstMatch(name); + // Check for unsupported iPads. + Match iPadMatch = new RegExp(r'iPad (2|Retina)', caseSensitive: false).firstMatch(name); + if (iPadMatch != null) { + _supportMessage = 'Flutter does not yet support iPad 2 or iPad Retina. Select an iPad Air or above.'; + return false; + } - // Not an iPhone. All available non-iPhone simulators are compatible. - if (match == null) - return true; + // Check for unsupported iPhones. + Match iPhoneMatch = new RegExp(r'iPhone [0-5]').firstMatch(name); + if (iPhoneMatch != null) { + if (name == 'iPhone 5s') + return true; + _supportMessage = 'Flutter does not support yet iPhone 5 or earlier. Select an iPhone 5s or above.'; + return false; + } - // iPhones 6 and above are always fine. - if (int.parse(match.group(1)) > 5) - return true; - - // The 's' subtype of 5 is compatible. - if (name.contains('iPhone 5s')) - return true; - - _supportMessage = 'The simulator version is too old. Choose an iPhone 5s or above.'; - return false; + return true; } String _supportMessage; diff --git a/packages/flutter_tools/test/src/ios/simulators_test.dart b/packages/flutter_tools/test/src/ios/simulators_test.dart index 1a71174b79..cb73c6a7d1 100644 --- a/packages/flutter_tools/test/src/ios/simulators_test.dart +++ b/packages/flutter_tools/test/src/ios/simulators_test.dart @@ -51,4 +51,38 @@ void main() { } }); }); + + group('IOSSimulator.isSupported', () { + test('Apple TV is unsupported', () { + expect(new IOSSimulator('x', name: 'Apple TV').isSupported(), false); + }); + + test('Apple Watch is unsupported', () { + expect(new IOSSimulator('x', name: 'Apple Watch').isSupported(), false); + }); + + test('iPad 2 is unsupported', () { + expect(new IOSSimulator('x', name: 'iPad 2').isSupported(), false); + }); + + test('iPad Retina is unsupported', () { + expect(new IOSSimulator('x', name: 'iPad Retina').isSupported(), false); + }); + + test('iPhone 5 is unsupported', () { + expect(new IOSSimulator('x', name: 'iPhone 5').isSupported(), false); + }); + + test('iPhone 5s is supported', () { + expect(new IOSSimulator('x', name: 'iPhone 5s').isSupported(), true); + }); + + test('iPhone SE is supported', () { + expect(new IOSSimulator('x', name: 'iPhone SE').isSupported(), true); + }); + + test('iPhone 7 Plus is supported', () { + expect(new IOSSimulator('x', name: 'iPhone 7 Plus').isSupported(), true); + }); + }); }