umair13adil / simple_beacons_flutter

A flutter plugin project to range & monitor iBeacons.
Apache License 2.0
35 stars 42 forks source link

iOS App Freezes With "White Screen" On Startup #70

Open ibcoleman opened 1 year ago

ibcoleman commented 1 year ago

Hi I just updated xcode, flutter, the ios version on my device, and my Flutter application which uses beacons_plugin after not touching it for a few months.

Sometimes I get the following exception in the log, but sometimes not. When I run the app in debug mode, it works without fail. If I run it with flutter run --release it hangs with a "white screen" on startup about 3 times out of 4.

I'm at the end of my rope, so any help truly appreciated!

I'm seeing the following in the console log from Runner:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method addRegion on channel beacons_plugin)
#0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:313)
<asynchronous suspension>
#1      BeaconsPlugin.addRegion (package:beacons_plugin/beacons_plugin.dart:35)
<asynchronous suspension>

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method startMonitoring on channel beacons_plugin)
#0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:313)
<asynchronous suspension>
#1      BeaconsPlugin.startMonitoring (package:beacons_plugin/beacons_plugin.dart:25)
<asynchronous suspension>
#2      BeaconBackgroundScanner.startScanning (package:asset_management_mobile/ui/beacon_background_scanner.dart:98)
<asynchronous suspension>
#3      main (package:asset_management_mobile/main.dart:79)
<asynchronous suspension>

If I comment out my beacons_plugin initialization method call things work 100% of the time. Here's the init method:

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    if (Platform.isAndroid) {
      //Prominent disclosure
      await BeaconsPlugin.setDisclosureDialogMessage(
          title: "Need Location Permission",
          message: "This app collects location data to work with beacons.");

      //Only in case, you want the dialog to be shown again. By Default, dialog will never be shown if permissions are granted.
      //await BeaconsPlugin.clearDisclosureDialogShowFlag(false);
    }

    //TODO: Add `await` keyword here? Comment out everything?
    BeaconsPlugin.listenToBeacons(beaconEventsController);

    //TODO: Remove `await` keyword here?
    await Future.forEach<BeaconRegion>(
        appStateModel.beaconScanState.regions, (element) {
          log.fine("Adding region ${element.name}");
          BeaconsPlugin.addRegion(element.name, element.uuid);
        }
    );

    // Register the callback to listen on the stream of beacons coming back.
    beaconEventsController.stream.listen((data) {
      if (data.isNotEmpty) {
        final beaconInfo = BeaconInfo.fromJson(jsonDecode(data));
        if (beaconInfo.isAnchor(appStateModel.beaconScanState.anchors)) {
          appStateModel.beaconScanState.addAnchor(BeaconAnchorEvent.fromBeaconInfo(
              beaconInfo: beaconInfo,
              longitude: locStateModel?.longitude,
              latitude: locStateModel?.latitude,
              timestamp: DateTime.now())
          );
        } else {
          appStateModel.beaconScanState.addBeacon(TagReadEvent.fromBeaconInfo(
              beaconInfo: beaconInfo,
              longitude: locStateModel?.longitude,
              latitude: locStateModel?.latitude,
              accuracy: locStateModel?.accuracy)
          );
        }
      }
    },
        onDone: () {
          log.info("Called onDone() beaconEventsController.stream.listen");
        },
        onError: (error) {
          log.severe("Error: $error");
        }
    );

    //Send 'true' to run in background
    await BeaconsPlugin.runInBackground(true);
  }

Here's the contents of flutter doctor -v:

[✓] Flutter (Channel master, 3.5.0-2.0.pre.19, on macOS 12.6 21G115 darwin-x64, locale en-US)
    • Flutter version 3.5.0-2.0.pre.19 on channel master at /Users/bob/Applications/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 98c0498796 (29 hours ago), 2022-10-06 08:33:25 -0400
    • Engine revision e72434025f
    • Dart version 2.19.0 (build 2.19.0-283.0.dev)
    • DevTools version 2.18.0

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/bob/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A400
    • CocoaPods version 1.11.3

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

[✓] Android Studio (version 2021.2)
    • Android Studio at /Users/bob/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-1/212.5712.43.2112.8815526/Android Studio Preview.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 11.0.12+0-b1504.28-7817840)

[✓] Android Studio (version 2021.2)
    • Android Studio at /Users/bob/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-1/212.5712.43.2112.8609683/Android Studio Preview.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 11.0.12+0-b1504.28-7817840)

[✓] Android Studio
    • Android Studio at /Users/bob/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/212.5712.43.2112.8184640/Android Studio Preview.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 11.0.12+0-b1504.28-7817840)

[✓] Android Studio
    • Android Studio at /Users/bob/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-2/213.6777.52.2113.8233036/Android Studio Preview.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 11.0.13+0-b1751.21-8125866)

[✓] Android Studio
    • Android Studio at /Users/bob/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-2/212.5457.46.2112.7968471/Android Studio Preview.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 11.0.12+0-b1504.28-7817840)

[✓] Android Studio
    • Android Studio at /Users/bob/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/211.7628.21.2111.7956428/Android Studio Preview.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 11.0.11+0-b60-7590822)

[✓] IntelliJ IDEA Ultimate Edition (version 2022.2.3)
    • IntelliJ at /Users/bob/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 70.2.5
    • Dart plugin version 222.4345.14

[✓] IntelliJ IDEA Ultimate Edition (version 2022.2.3)
    • IntelliJ at /Users/bob/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/222.4345.14/IntelliJ IDEA.app
    • 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

[✓] IntelliJ IDEA Ultimate Edition (version 2022.2.2)
    • IntelliJ at /Users/bob/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/222.4167.29/IntelliJ IDEA.app
    • 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

[✓] IntelliJ IDEA Ultimate Edition (version EAP IU-221.5080.9)
    • IntelliJ at /Users/bob/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-1/221.5080.9/IntelliJ IDEA 2022.1 EAP.app
    • 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

[✓] IntelliJ IDEA Ultimate Edition (version EAP IU-221.4994.44)
    • IntelliJ at /Users/bob/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-1/221.4994.44/IntelliJ IDEA 2022.1 EAP.app
    • 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

[✓] Connected device (3 available)
    • Bob's iPhone XS (mobile) • 00008020-001221820C33002E • ios            • iOS 16.0 20A362
    • macOS (desktop)          • macos                     • darwin-x64     • macOS 12.6 21G115 darwin-x64
    • Chrome (web)             • chrome                    • web-javascript • Google Chrome 106.0.5249.103
    ! Error: (null) needs to connect to determine its availability. Check the connection between the device and its companion iPhone, and the connection between the iPhone and Xcode. Both devices may
      also need to be restarted and unlocked. (code 1)

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.