解决 Flutter lost connection to device

25 min read

flutter 仅仅显示如下内容

Launching lib/main.dart on iPhone 12 in debug mode...
Running pod install...
Running Xcode build...
Xcode build done.                                           37.0s
Waiting for iPhone 11 to report its views...
Debug service listening on ws://127.0.0.1:65405/L1H3N-Q0JFU=/ws
Syncing files to device iPhone 12...
Lost connection to device.

使用 xcode 打开显示了具体的报错信息

2022-07-25 09:25:17.486053+0800 Runner[20667:81570] Metal API Validation Enabled
2022-07-25 09:25:17.701806+0800 Runner[20667:82176] flutter: The Dart VM service is listening on http://127.0.0.1:53678/9QfPKEiA-DU=/
2022-07-25 09:25:18.949918+0800 Runner[20667:81570] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'To use location in iOS8 and above you need to define either NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription in the app bundle's Info.plist file'
*** First throw call stack:
(
	0   CoreFoundation                      0x00000001042e4604 __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x0000000101193a45 objc_exception_throw + 48
	2   CoreFoundation                      0x00000001042e44e2 -[NSException initWithCoder:] + 0
	3   location                            0x00000001008d9997 -[LocationPlugin requestPermission] + 375
	4   location                            0x00000001008d9431 -[LocationPlugin handleMethodCall:result:] + 4465
	5   Flutter                             0x000000010842ff81 __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 104
	6   Flutter                             0x0000000107e6eef2 ___ZN7flutter25PlatformMessageHandlerIos21HandlePlatformMessageENSt3__110unique_ptrINS_15PlatformMessageENS1_14default_deleteIS3_EEEE_block_invoke + 86
	7   libdispatch.dylib                   0x000000010412b816 _dispatch_call_block_and_release + 12
	8   libdispatch.dylib                   0x000000010412ca5b _dispatch_client_callout + 8
	9   libdispatch.dylib                   0x000000010413b325 _dispatch_main_queue_drain + 1169
	10  libdispatch.dylib                   0x000000010413ae86 _dispatch_main_queue_callback_4CF + 31
	11  CoreFoundation                      0x0000000104250ed5 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
	12  CoreFoundation                      0x000000010424b6ca __CFRunLoopRun + 2761
	13  CoreFoundation                      0x000000010424a704 CFRunLoopRunSpecific + 562
	14  GraphicsServices                    0x0000000107d11c8e GSEventRunModal + 139
	15  UIKitCore                           0x000000011abc965a -[UIApplication _run] + 928
	16  UIKitCore                           0x000000011abce2b5 UIApplicationMain + 101
	17  Runner                              0x00000001003180cf main + 63
	18  dyld                                0x0000000100532f21 start_sim + 10
	19  ???                                 0x0000000107d8151e 0x0 + 4426568990
)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_ROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot DYLD_LIBRARY_PATH=/Users/pan/Library/Developer/Xcode/DerivedData/Runner-dguavirrkdgyvediywctbbomropz/Build/Products/Debug-iphonesimulator:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libMainThreadChecker.dylib:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib DYLD_FRAMEWORK_PATH=/Users/pan/Library/Developer/Xcode/DerivedData/Runner-dguavirrkdgyvediywctbbomropz/Build/Products/Debug-iphonesimulator
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'To use location in iOS8 and above you need to define either NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription in the app bundle's Info.plist file'
terminating with uncaught exception of type NSException
CoreSimulator 802.6.1 - Device: iPhone 12 (A651AAA9-D210-427F-942C-052524BBCAD7) - Runtime: iOS 15.5 (19F70) - DeviceType: iPhone 12
(lldb) 

报错显示要添加ios的定位权限