Meg*_*tha 11 xcode exception ios swift flutter
我刚刚将 XCode 更新到版本 15,遇到此错误(仅限 17 以下的 iOS 版本)\xc2\xa0
\nThread 1: EXC_BAD_ACCESS (code=1, address=0x0)\nRun Code Online (Sandbox Code Playgroud)\n显示此错误的代码(PathMonitorConectivityProvider.swift):
\n当我从 XCode 运行代码时(iOS 设备版本是 iOS 16.4),以下代码中出现异常。
\nimport Foundation\nimport Network\n\n@available(iOS 12, *)\npublic class PathMonitorConnectivityProvider: NSObject, ConnectivityProvider {\n\n private let queue = DispatchQueue.global(qos: .background)\n\n private var _pathMonitor: NWPathMonitor?\n\n public var currentConnectivityType: ConnectivityType {\n let path = ensurePathMonitor().currentPath\n // .satisfied means that the network is available\n if path.status == .satisfied {\n if path.usesInterfaceType(.wifi) {\n return .wifi\n } else if path.usesInterfaceType(.cellular) {\n return .cellular\n } else if path.usesInterfaceType(.wiredEthernet) {\n // .wiredEthernet is available in simulator\n // but for consistency it is probably correct to report .wifi\n return .wifi\n } else if path.usesInterfaceType(.other) {\n return .other\n }\n }\n return .none\n }\n\n public var connectivityUpdateHandler: ConnectivityUpdateHandler?\n\n override init() {\n super.init()\n _ = ensurePathMonitor()\n }\n\n public func start() {\n _ = ensurePathMonitor()\n }\n\n public func stop() {\n _pathMonitor?.cancel()\n _pathMonitor = nil\n }\n\n @discardableResult\n private func ensurePathMonitor() -> NWPathMonitor {\n if (_pathMonitor == nil) {\n let pathMonitor = NWPathMonitor()\n pathMonitor.start(queue: queue)\n pathMonitor.pathUpdateHandler = pathUpdateHandler\n _pathMonitor = pathMonitor\n }\n return _pathMonitor!\n }\n\n private func pathUpdateHandler(path: NWPath) {\n connectivityUpdateHandler?(currentConnectivityType)\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n另外 Flutter doctor 结果:
\nDoctor summary (to see all details, run flutter doctor -v):\n[\xe2\x9c\x93] Flutter (Channel stable, 3.13.4, on macOS 13.5.2 22G91 darwin-x64, locale en-LK)\n[\xe2\x9c\x93] Android toolchain - develop for Android devices (Android SDK version 33.0.1)\n[\xe2\x9c\x93] Xcode - develop for iOS and macOS (Xcode 15.0)\n[\xe2\x9c\x93] Chrome - develop for the web\n[\xe2\x9c\x93] Android Studio (version 2022.1)\n[\xe2\x9c\x93] IntelliJ IDEA Community Edition (version 2022.3.2)\n[\xe2\x9c\x93] VS Code (version 1.82.2)\n[\xe2\x9c\x93] Connected device (4 available)\n[\xe2\x9c\x93] Network resources\n\n\xe2\x80\xa2 No issues found!\nRun Code Online (Sandbox Code Playgroud)\n另外AppDelegate.swift:
\nimport UIKit\nimport Flutter\nimport GoogleMaps\n\n@UIApplicationMain\n@objc class AppDelegate: FlutterAppDelegate {\n override func application(\n _ application: UIApplication,\n didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?\n ) -> Bool {\n GMSServices.provideAPIKey("AIzaSyB0SHZK3ngwOu0r26fm3pOrhKumXS7XdHY")\n GeneratedPluginRegistrant.register(with: self)\n return super.application(application, didFinishLaunchingWithOptions: launchOptions)\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n
Flo*_*scu 14
解决方案是升级 Pods 项目上的所有库,包括Flutter从IOS Deployment Target 11.0到 版本12.0或更高版本。由于某些原因,XCode 15 会将所有版本降级到 9.0 或 11.0,这将导致您的项目混乱并出现类似这样的奇怪错误。
小智 7
我在 Xcode 15 中遇到了同样的问题,事实上,将iOS 部署目标从 11.0 更改为 12.0 为我解决了这个问题。但是,没有必要为每个包手动执行此操作 - 您只需将脚本添加到 Podfile 即可:
post_install do |installer|
installer.generated_projects.each do |project|
project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
end
end
end
Run Code Online (Sandbox Code Playgroud)
要更新您的 Pod,请在项目的 ios 文件夹中使用以下命令:
pod cache clean --all
pod deintegrate
rm -f Podfile.lock
pod install --repo-update
Run Code Online (Sandbox Code Playgroud)
PS 明年当我们获得 Xcode 16 和 iOS 18 时,准备好再次将其更改为 13.0 =)
| 归档时间: |
|
| 查看次数: |
5160 次 |
| 最近记录: |