Commit fb72f21c authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

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.
parent 104fcf8d
...@@ -369,9 +369,8 @@ class IOSSimulator extends Device { ...@@ -369,9 +369,8 @@ class IOSSimulator extends Device {
// We do not support WatchOS or tvOS devices. // We do not support WatchOS or tvOS devices.
RegExp blacklist = new RegExp(r'Apple (TV|Watch)', caseSensitive: false); RegExp blacklist = new RegExp(r'Apple (TV|Watch)', caseSensitive: false);
if (blacklist.hasMatch(name)) { 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; return false;
} }
...@@ -380,23 +379,23 @@ class IOSSimulator extends Device { ...@@ -380,23 +379,23 @@ class IOSSimulator extends Device {
// targeted applications cannot be run (even though the Flutter // targeted applications cannot be run (even though the Flutter
// runner on the simulator is completely different). // runner on the simulator is completely different).
RegExp versionExp = new RegExp(r'iPhone ([0-9])+'); // Check for unsupported iPads.
Match match = versionExp.firstMatch(name); Match iPadMatch = new RegExp(r'iPad (2|Retina)', caseSensitive: false).firstMatch(name);
if (iPadMatch != null) {
// Not an iPhone. All available non-iPhone simulators are compatible. _supportMessage = 'Flutter does not yet support iPad 2 or iPad Retina. Select an iPad Air or above.';
if (match == null) return false;
return true; }
// iPhones 6 and above are always fine.
if (int.parse(match.group(1)) > 5)
return true;
// The 's' subtype of 5 is compatible. // Check for unsupported iPhones.
if (name.contains('iPhone 5s')) Match iPhoneMatch = new RegExp(r'iPhone [0-5]').firstMatch(name);
return true; 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;
}
_supportMessage = 'The simulator version is too old. Choose an iPhone 5s or above.'; return true;
return false;
} }
String _supportMessage; String _supportMessage;
......
...@@ -51,4 +51,38 @@ void main() { ...@@ -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);
});
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment