@@ -22,7 +22,7 @@ import 'mac.dart';
22
22
const String _xcrunPath = '/usr/bin/xcrun' ;
23
23
24
24
/// Test device created by Flutter when no other device is available.
25
- const String _kFlutterTestDevice = 'flutter.test.device ' ;
25
+ const String _kFlutterTestDeviceSuffix = '(Flutter) ' ;
26
26
27
27
class IOSSimulators extends PollingDeviceDiscovery {
28
28
IOSSimulators () : super ('IOSSimulators' );
@@ -97,7 +97,7 @@ class SimControl {
97
97
}
98
98
99
99
SimDevice _createTestDevice () {
100
- String deviceType = _findSuitableDeviceType ();
100
+ SimDeviceType deviceType = _findSuitableDeviceType ();
101
101
if (deviceType == null ) {
102
102
return null ;
103
103
}
@@ -109,18 +109,19 @@ class SimControl {
109
109
110
110
// Delete any old test devices
111
111
getDevices ()
112
- .where ((SimDevice d) => d.name == _kFlutterTestDevice )
112
+ .where ((SimDevice d) => d.name. endsWith (_kFlutterTestDeviceSuffix) )
113
113
.forEach (_deleteDevice);
114
114
115
115
// Create new device
116
- List <String > args = [_xcrunPath, 'simctl' , 'create' , _kFlutterTestDevice, deviceType, runtime];
116
+ String deviceName = '${deviceType .name } $_kFlutterTestDeviceSuffix ' ;
117
+ List <String > args = [_xcrunPath, 'simctl' , 'create' , deviceName, deviceType.identifier, runtime];
117
118
printTrace (args.join (' ' ));
118
119
runCheckedSync (args);
119
120
120
- return getDevices ().firstWhere ((SimDevice d) => d.name == _kFlutterTestDevice );
121
+ return getDevices ().firstWhere ((SimDevice d) => d.name == deviceName );
121
122
}
122
123
123
- String _findSuitableDeviceType () {
124
+ SimDeviceType _findSuitableDeviceType () {
124
125
List <Map <String , dynamic >> allTypes = _list (SimControlListSection .devicetypes);
125
126
List <Map <String , dynamic >> usableTypes = allTypes
126
127
.where ((Map <String , dynamic > info) => info['name' ].startsWith ('iPhone' ))
@@ -136,7 +137,10 @@ class SimControl {
136
137
);
137
138
}
138
139
139
- return usableTypes.first['identifier' ];
140
+ return new SimDeviceType (
141
+ usableTypes.first['name' ],
142
+ usableTypes.first['identifier' ]
143
+ );
140
144
}
141
145
142
146
String _findSuitableRuntime () {
@@ -300,6 +304,30 @@ class SimControlListSection {
300
304
static const SimControlListSection pairs = const SimControlListSection ._('pairs' );
301
305
}
302
306
307
+ /// A simulated device type.
308
+ ///
309
+ /// Simulated device types can be listed using the command
310
+ /// `xcrun simctl list devicetypes` .
311
+ class SimDeviceType {
312
+ SimDeviceType (this .name, this .identifier);
313
+
314
+ /// The name of the device type.
315
+ ///
316
+ /// Examples:
317
+ ///
318
+ /// "iPhone 6s"
319
+ /// "iPhone 6 Plus"
320
+ final String name;
321
+
322
+ /// The identifier of the device type.
323
+ ///
324
+ /// Examples:
325
+ ///
326
+ /// "com.apple.CoreSimulator.SimDeviceType.iPhone-6s"
327
+ /// "com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus"
328
+ final String identifier;
329
+ }
330
+
303
331
class SimDevice {
304
332
SimDevice (this .category, this .data);
305
333
0 commit comments