swift Error encountered only below iOS 17 devices“Thread 1:EXC_BAD_ACCESS(代码=1,地址=0x0)”

piv4azn7  于 2023-09-30  发布在  Swift
关注(0)|答案(2)|浏览(304)

我刚刚将我的XCode更新到版本15,我遇到了这个错误(仅限17以下的iOS版本)

Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)

显示此错误的代码(PathMonitorConectivityProvider.swift):
当我从XCode(iOS设备版本是iOS 16.4)运行代码时,下面的代码中出现了一个异常。

import Foundation
import Network

@available(iOS 12, *)
public class PathMonitorConnectivityProvider: NSObject, ConnectivityProvider {

  private let queue = DispatchQueue.global(qos: .background)

  private var _pathMonitor: NWPathMonitor?

  public var currentConnectivityType: ConnectivityType {
    let path = ensurePathMonitor().currentPath
    // .satisfied means that the network is available
    if path.status == .satisfied {
      if path.usesInterfaceType(.wifi) {
        return .wifi
      } else if path.usesInterfaceType(.cellular) {
        return .cellular
      } else if path.usesInterfaceType(.wiredEthernet) {
        // .wiredEthernet is available in simulator
        // but for consistency it is probably correct to report .wifi
        return .wifi
      } else if path.usesInterfaceType(.other) {
        return .other
      }
    }
    return .none
  }

  public var connectivityUpdateHandler: ConnectivityUpdateHandler?

  override init() {
    super.init()
    _ = ensurePathMonitor()
  }

  public func start() {
    _ = ensurePathMonitor()
  }

  public func stop() {
    _pathMonitor?.cancel()
    _pathMonitor = nil
  }

  @discardableResult
  private func ensurePathMonitor() -> NWPathMonitor {
    if (_pathMonitor == nil) {
      let pathMonitor = NWPathMonitor()
      pathMonitor.start(queue: queue)
      pathMonitor.pathUpdateHandler = pathUpdateHandler
      _pathMonitor = pathMonitor
    }
    return _pathMonitor!
  }

  private func pathUpdateHandler(path: NWPath) {
    connectivityUpdateHandler?(currentConnectivityType)
  }
}

Screen shot of the error
此外,Flutter医生结果:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.13.4, on macOS 13.5.2 22G91 darwin-x64, locale en-LK)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.1)
[✓] IntelliJ IDEA Community Edition (version 2022.3.2)
[✓] VS Code (version 1.82.2)
[✓] Connected device (4 available)
[✓] Network resources

• No issues found!

AppDelegate.swift:

import UIKit
import Flutter
import GoogleMaps

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GMSServices.provideAPIKey("AIzaSyB0SHZK3ngwOu0r26fm3pOrhKumXS7XdHY")
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}
ddrv8njm

ddrv8njm1#

解决方案是升级Pods项目中的所有库,包括从IOS Deployment Target 11.0升级到12.0或更高版本的Flutter。由于某些原因,XCode 15会将所有版本降级到9.0或11.0,这会导致项目混乱和类似的奇怪错误。

mu0hgdu0

mu0hgdu02#

这里是XCode 15,我遇到了类似的错误,我发现的是在TARGET'S RUNNER中将最低部署目标更改为比IOS 11.x更高的版本(我已经更改为iOS 13.0),单独更改每个库对我不起作用,可能是因为Xcode在构建应用程序时将这些库降级为较低版本(idk为什么这样工作)。

相关问题