skip to Main Content

I’ve just updated my XCode to version 15, and I encountered this error (only iOS versions below 17) 

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

code that shows this error (PathMonitorConectivityProvider.swift):

When I ran my code from XCode (the iOS device version is iOS 16.4), an exception occurred in the below code.

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

Additionally Flutter doctor results:

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!

Additionally 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)
  }
}

2

Answers


  1. The solution is to upgrade all your libraries on the Pods project, inclusive Flutter from IOS Deployment Target 11.0 to version 12.0 or higher.
    For some reasons XCode 15 will downgrade all the versions to 9.0 or 11.0 which will cause chaos in your project and strange errors like this.

    enter image description here

    Login or Signup to reply.
  2. XCode 15 here, I had similar error and what I figured out is to change minimum deployment target to higher version than IOS 11.x in TARGET’S RUNNER (I’ve changed to iOS 13.0), changing each library separately didn’t work for me, probably because Xcode downgrades those libs to lower version while building app (idk why this is working that way).

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search