fluttercommunity / plus_plugins

Flutter Community Plus Plugins
BSD 3-Clause "New" or "Revised" License
1.61k stars 973 forks source link

[Bug]: App crashes while initializing PathMonitorConnectivityProvider on iPad/iPhone 16.7 #2606

Closed timobaehr closed 8 months ago

timobaehr commented 8 months ago

Platform

iOS 16.7.4 iOS 16.7.5

Plugin

connectivity_plus

Version

5.0.2

Flutter SDK

3.16.9

Steps to reproduce

The app fails to run the iPad Pro with iOS 16.7.4 installed via Testflight. The app also crashes on real iPhone with iOS 16.7.5. It works on iPad simulator with 16.4.

  1. Use connectivity in the project
  2. Run on iPad or iPhone with iOS 16.7.4/16.7.5

IS: App crashes at app start. SHOULD: App should open.

Code Sample

import Flutter

public class SwiftConnectivityPlusPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
  public static func register(with registrar: FlutterPluginRegistrar) {
    let channel = FlutterMethodChannel(
      name: "dev.fluttercommunity.plus/connectivity",
      binaryMessenger: registrar.messenger())

    let streamChannel = FlutterEventChannel(
      name: "dev.fluttercommunity.plus/connectivity_status",
      binaryMessenger: registrar.messenger())

    let connectivityProvider: ConnectivityProvider
    if #available(iOS 12, *) {
      connectivityProvider = PathMonitorConnectivityProvider() // <-- Crash!
    } else {
      connectivityProvider = ReachabilityConnectivityProvider()
    }

    let instance = SwiftConnectivityPlusPlugin(connectivityProvider: connectivityProvider)
    streamChannel.setStreamHandler(instance)

    registrar.addMethodCallDelegate(instance, channel: channel)
  }

}

Logs

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Codes: 0x0000000000000001, 0x0000000000000000
VM Region Info: 0 is not in any region.  Bytes before following region: 4370120704
      REGION TYPE                 START - END      [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                   1047ac000-1047b0000 [   16K] r-x/r-x SM=COW  ...er.app/Runner
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler [34578]

Triggered by Thread:  0

Thread 0 name:
Thread 0 Crashed:
0   ???                             0x0000000000000000 0x0 + 0
1   connectivity_plus               0x0000000105934a60 @objc PathMonitorConnectivityProvider.init() + 20 (<compiler-generated>:0)
2   connectivity_plus               0x0000000105936334 PathMonitorConnectivityProvider.__allocating_init() + 24 (PathMonitorConnectivityProvider.swift:0)
3   connectivity_plus               0x0000000105936334 specialized static SwiftConnectivityPlusPlugin.register(with:) + 308 (SwiftConnectivityPlusPlugin.swift:28)
4   connectivity_plus               0x0000000105935844 static SwiftConnectivityPlusPlugin.register(with:) + 8 (<compiler-generated>:0)
5   connectivity_plus               0x0000000105935844 @objc static SwiftConnectivityPlusPlugin.register(with:) + 32

Flutter Doctor

[!] Flutter (Channel stable, 3.19.0, on macOS 14.3 23D56 darwin-arm64, locale de-DE)
    • Flutter version 3.19.0 on channel stable at /Users/timo/flutter
    ! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/3.1.5/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/timo/flutter. Consider adding /Users/timo/flutter/bin to the front of
      your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision bae5e49bc2 (4 days ago), 2024-02-13 17:46:18 -0800
    • Engine revision 04817c99c9
    • Dart version 3.3.0
    • DevTools version 2.31.1
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/timo/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code (version 1.86.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.56.0

Checklist before submitting a bug

timobaehr commented 8 months ago

This bug looks a little bit like this one: https://github.com/fluttercommunity/plus_plugins/issues/2136

vbuberen commented 8 months ago

This crash happens for projects that have deployment version lower than 12. This is not a bug in the plugin. Update your project setup to have iOS 12 as min deployment target.

timobaehr commented 8 months ago

Thank you for the work response. App can be opened again from first testers.