flutter_background_service icon indicating copy to clipboard operation
flutter_background_service copied to clipboard

Use of path_provider in background on iOS gives issues

Open Henk-Keijzer opened this issue 3 years ago • 3 comments
trafficstars

Hi,

I get the following error:

2022-03-01 11:14:50.632181+0100 Runner[1070:257679] Metal API Validation Enabled 2022-03-01 11:14:50.877308+0100 Runner[1070:257941] [VERBOSE-2:ui_dart_state.cc(198)] Unhandled Exception: MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider_ios) #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:165) #1 getApplicationDocumentsDirectory (package:path_provider/path_provider.dart:115) #2 onBackgroundStart (package:szwmobiletracker/main.dart:119)

I thought the problem was with the path-provider (and path-provider-ios), but it seems to be something related to registering a package (somewhere?). See https://github.com/flutter/flutter/issues/99155#issuecomment-1055288089 and subsequent communications with Stuart Morgan.

Can you help???

Henk-Keijzer avatar Mar 01 '22 15:03 Henk-Keijzer

try to call this https://github.com/flutter/flutter/issues/99155#issuecomment-1052023743 in onBackgroundServiceStart. If the error still occured, try to register plugins in native side. See: https://github.com/ekasetiawans/flutter_background_service/blob/master/example/ios/Runner/AppDelegate.swift

ekasetiawans avatar Mar 01 '22 23:03 ekasetiawans

try to call this flutter/flutter#99155 (comment) in onBackgroundServiceStart.

The error message is about plugins.flutter.io/path_provider_ios, which means the Dart registration has successfully run in this scenario.

stuartmorgan-g avatar Mar 03 '22 21:03 stuartmorgan-g

@stuartmorgan the root cause is the MethodChannelHandler in native side is not registered to the FlutterEngine. I use separated FlutterEngine to execute background task.

ekasetiawans avatar Mar 04 '22 05:03 ekasetiawans