Skip to content

Commit aba0c4e

Browse files
authored
Do not show diagnostic warning for disconnected iOS devices (#105971)
1 parent a4f817c commit aba0c4e

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

packages/flutter_tools/lib/src/macos/xcdevice.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,10 @@ class XCDevice {
354354
return error is Map<String, Object?> ? error : null;
355355
}
356356

357-
static int? _errorCode(Map<String, Object?> errorProperties) {
357+
static int? _errorCode(Map<String, Object?>? errorProperties) {
358+
if (errorProperties == null) {
359+
return null;
360+
}
358361
final Object? code = errorProperties['code'];
359362
return code is int ? code : null;
360363
}
@@ -521,6 +524,14 @@ class XCDevice {
521524
final Map<String, Object?>? errorProperties = _errorProperties(deviceProperties);
522525
final String? errorMessage = _parseErrorMessage(errorProperties);
523526
if (errorMessage != null) {
527+
final int? code = _errorCode(errorProperties);
528+
// Error -13: iPhone is not connected. Xcode will continue when iPhone is connected.
529+
// This error is confusing since the device is not connected and maybe has not been connected
530+
// for a long time. Avoid showing it.
531+
if (code == -13 && errorMessage.contains('not connected')) {
532+
continue;
533+
}
534+
524535
diagnostics.add(errorMessage);
525536
}
526537
}

packages/flutter_tools/test/general.shard/macos/xcode_test.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,35 @@ void main() {
788788
"recoverySuggestion" : "Xcode will continue when iPhone is finished.",
789789
"domain" : "com.apple.platform.iphoneos"
790790
}
791+
},
792+
{
793+
"modelCode" : "iPad8,5",
794+
"simulator" : false,
795+
"modelName" : "iPad Pro (12.9-inch) (3rd generation)",
796+
"error" : {
797+
"code" : -13,
798+
"failureReason" : "",
799+
"underlyingErrors" : [
800+
{
801+
"code" : 4,
802+
"failureReason" : "",
803+
"description" : "iPad is locked.",
804+
"recoverySuggestion" : "To use iPad with Xcode, unlock it.",
805+
"domain" : "DVTDeviceIneligibilityErrorDomain"
806+
}
807+
],
808+
"description" : "iPad is not connected",
809+
"recoverySuggestion" : "Xcode will continue when iPad is connected.",
810+
"domain" : "com.apple.platform.iphoneos"
811+
},
812+
"operatingSystemVersion" : "15.6 (19G5027e)",
813+
"identifier" : "00008027-0019253601068123",
814+
"platform" : "com.apple.platform.iphoneos",
815+
"architecture" : "arm64e",
816+
"interface" : "usb",
817+
"available" : false,
818+
"name" : "iPad",
819+
"modelUTI" : "com.apple.ipad-pro-12point9-1"
791820
}
792821
]
793822
''';
@@ -799,10 +828,12 @@ void main() {
799828

800829
final List<String> errors = await xcdevice.getDiagnostics();
801830
expect(errors, hasLength(4));
831+
802832
expect(errors[0], 'Error: iPhone is not paired with your computer. To use iPhone with Xcode, unlock it and choose to trust this computer when prompted. (code -9)');
803833
expect(errors[1], 'Error: iPhone is not paired with your computer.');
804834
expect(errors[2], 'Error: Xcode pairing error. (code -13)');
805835
expect(errors[3], 'Error: iPhone is busy: Preparing debugger support for iPhone. Xcode will continue when iPhone is finished. (code -10)');
836+
expect(errors, isNot(contains('Xcode will continue')));
806837
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
807838
}, overrides: <Type, Generator>{
808839
Platform: () => macPlatform,

0 commit comments

Comments
 (0)