fluttercommunity / flutter_workmanager

A Flutter plugin which allows you to execute code in the background on Android and iOS.
829 stars 247 forks source link

🐞[iOS] MissingPluginException in example app #189

Closed gebsl closed 3 years ago

gebsl commented 4 years ago

Version

Technology Version
Workmanager version 0.2.3
Xcode version 11.5
Swift version 5.0
iOS deployment target 13.5.1 (iPhone SE 1st Generation)

Describe the error

When running the example app on a real iOS device through XCode (by pressing the "Run" icon), the app throws an exception when pressing the "Start the Flutter background service" button. Subsequently, background fetch won't work and the dispatch method is never called.

The exception in XCode's console is:

2020-07-15 23:46:23.059914+0200 Runner[9411:4096136] [VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method initialize on channel be.tramckrijte.workmanager/foreground_channel_work_manager)
#0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:154:7)
<asynchronous suspension>
#1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
#2      Workmanager.initialize (package:workmanager/src/workmanager.dart:100:30)
#3      _MyAppState.build.<anonymous closure> (package:workmanager_example/main.dart:87:33)
#4      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:779:19)
#5      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:862:36)
#6      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
#7      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:504:11)
#8      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:282:5)
#9      BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:217:7)
#10     PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:475:9)
#11     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12)
#12     PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:122:9)
#13     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8)
#14     PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:120:18)
#15     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:106:7)
#16     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
#17     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
#18     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
#19     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
#20     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
#21     _rootRunUnary (dart:async/zone.dart:1196:13)
#22     _CustomZone.runUnary (dart:async/zone.dart:1085:19)
#23     _CustomZone.runUnaryGuarded (dart:async/zone.dart:987:7)
#24     _invoke1 (dart:ui/hooks.dart:275:10)
#25     _dispatchPointerDataPacket (dart:ui/hooks.dart:184:5)

Unfortunately I can not provide any debug information, when starting the app through flutter run, as there seems to be a bug with iOS hiding important exceptions from frameworks like flutter (see https://github.com/flutter/flutter/issues/41133), so the only way to fetch information (at least the one I know about) is through XCode.

Except from running flutter pub get and flutter build ios (to resolve initial build error in XCode) I didn't changed anything in the example app.

Though, there is one thing I noticed that's different from the iOS setup guide: After unchecking and re-checking the capability "Background fetch" in XCode, following block is not added to file project.pbxproj (which, as I understood, should be added automatically by XCode):

SystemCapabilities = {
    com.apple.BackgroundModes = {
        enabled = 1;
    };
};

Unfortunately, adding it manually does not seem to have any effect.

Output of flutter doctor -v

[✓] Flutter (Channel stable, v1.17.5, on Mac OS X 10.15.5 19F101, locale en-GB)
    • Flutter version 1.17.5 at /opt/flutter
    • Framework revision 8af6b2f038 (2 weeks ago), 2020-06-30 12:53:55 -0700
    • Engine revision ee76268252
    • Dart version 2.8.4

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from:
      https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK
      components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup
      for detailed instructions).
      If the Android SDK has been installed to a custom location, set
      ANDROID_SDK_ROOT to that location.
      You may also want to add it to your PATH environment variable.

[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.5, Build version 11E608c
    • CocoaPods version 1.9.3

[!] Android Studio (not installed)
    • Android Studio not found; download from
      https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup
      for detailed instructions).

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

[✓] Connected device (1 available)            
    • iPhone xxx xxxxxxxx • a196bfcb78b38a0f88a8xxxxxxxxxxxxxxxxxxx • ios •
      iOS 13.5.1
kimmy-wang commented 3 years ago

Why is there no SystemCapabilities attribute in this file project.pbxproj in my project?

ened commented 3 years ago

I have just verified this ticket can be closed - please see the Xcode screenshots:

Screen Shot 2021-04-29 at 20 38 23

And the resulting console logs after pressing that one:

Screen Shot 2021-04-29 at 20 38 28

Therefore closing this issue. Please open single, separate issues for specific questions or problems.