flutter_background_service
flutter_background_service copied to clipboard
iOS package inside onStart() function throws "missing plugin implementation" exception
Hi everybody. Inside the onStart() function I'm using methods and functio from an external package. On Android everything work fine, on iOS these methods from that package throw the "missing plugin implementation" exception. But if I don't use background_service and i run these methods normally in an app widget, they work. It's like inside the onStart() function iOS doesn't find that package. Someone has got the same problem? How can I fix it?
can you provide flutter doctor
output?
Ok i will give you as soon as I can
Il Sab 22 Gen 2022, 21:27 Eka Setiawan Saputra @.***> ha scritto:
can you provide flutter doctor output?
— Reply to this email directly, view it on GitHub https://github.com/ekasetiawans/flutter_background_service/issues/89#issuecomment-1019352580, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADEWB4M6GLQULZCETA3GDNLUXMHKNANCNFSM5MR3YDGA . You are receiving this because you authored the thread.Message ID: @.***>
Hello @ekasetiawans i'm facing the same issue here. This is my flutter doctor output:
Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 2.8.0, on macOS 12.1 21C52 darwin-x64, locale en-FR) [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 13.0) [✓] Chrome - develop for the web [✓] Android Studio (version 2020.3) [✓] VS Code (version 1.63.2) [✓] Connected device (2 available)
Sorry for the delay. Here is my flutter doctor:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.8.1, on Mac OS X 10.15.7 19H1217 darwin-x64, locale it-IT)
[✗] 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, please use
flutter config --android-sdk
to update to that location.
[!] Xcode - develop for iOS and macOS (Xcode 12.1) ! Flutter recommends a minimum Xcode version of 13.0.0. Download the latest version or update via the Mac App Store. [✓] Chrome - develop for the web [✓] Android Studio (version 3.1) [!] IntelliJ IDEA Community Edition (version 2016.2.5) ✗ This install is older than the minimum recommended version of 2017.1.0. [✓] VS Code (version 1.63.2) [✓] Connected device (2 available)
@bobosette have you call WidgetsFlutterBinding.ensureInitialized()
in onStart()
method?
Yes. I give you some code:
` void main() async { WidgetsFlutterBinding.ensureInitialized(); initializeService(); runApp(const MyApp()); }
void onIosBackground() { WidgetsFlutterBinding.ensureInitialized(); }
Future
// auto start service
autoStart: false,
isForegroundMode: true,
),
iosConfiguration: IosConfiguration(
// auto start service
autoStart: false,
// this will executed when app is in foreground in separated isolate
onForeground: onStart,
// you have to enable background fetch capability on xcode project
onBackground: onIosBackground,
),
); }
void onStart() { int count = 0;
WidgetsFlutterBinding.ensureInitialized();
//background service initialization
FlutterBackgroundService().onDataReceived.listen((event) async { if (event!["action"] == "setAsForeground") { FlutterBackgroundService().setForegroundMode(true); return; }
if (event["action"] == "setAsBackground") {
FlutterBackgroundService().setForegroundMode(false);
}
//model initialization TfliteAudio.loadModel( inputType: 'rawAudio', numThreads: 1, outputRawScores: true, isAsset: true, model: 'assets/cough_model.tflite', label: 'assets/cough_label.txt' );
// bring to foreground FlutterBackgroundService().setForegroundMode(true);
}
` TfliteAudio.loadModel() doesn't work inside the onstart()
@bobosette could you try to add commented code in https://github.com/ekasetiawans/flutter_background_service/blob/master/example/ios/Runner/AppDelegate.swift
Hello @ekasetiawans I'm getting this error : Type 'SwiftFlutterBackgroundServicePlugin' has no member 'setPluginRegistrantCallback' when i uncommented code in AppDelegate.swift which makes sense as it's no longer available in new versions.
@Habib-T4ULabs Thanks for the info. It seems a bug in plugin need to be fix but I don't have enough time to fix it now.
@ekasetiawans first of all thank you for your reactivity! could you please put me on the right track so i can try to fix it as i really need it for my next project delivery monday.
@Habib-T4ULabs you can always fork this repository, modify it, and then use your git repository url in your pubspec.yaml. If everything already done, you can create a pull request then I will merge it, so it will be available at pub.dev for everyone.
Guys when you have something ready to fix that, could you tell me please?
Il giorno gio 3 feb 2022 alle ore 10:21 Eka Setiawan Saputra < @.***> ha scritto:
@Habib-T4ULabs https://github.com/Habib-T4ULabs you can always fork this repository, modify it, and then use your git repository url in your pubspec.yaml. If everything already done, you can create a pull request then I will merge it, so it will be available at pub.dev for everyone.
— Reply to this email directly, view it on GitHub https://github.com/ekasetiawans/flutter_background_service/issues/89#issuecomment-1028772990, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADEWB4LHJ4QELCKSHP44UJDUZJCI7ANCNFSM5MR3YDGA . You are receiving this because you were mentioned.Message ID: @.***>
@ekasetiawans can you please give me the right steps to fix it as your functions are no longer available in the new versions ?
@ekasetiawans i forked the repository and tried what you proposed previously but still get the same error
@Habib-T4ULabs
any progress?
@paraslamsong i followed the steps that @ekasetiawans mentioned but still not working. I ended up including another package for IOS as Flutter background service still not stable on IOS platform.
@Habib-T4ULabs what package?
@bobosette I used this package (flutter_isolate 2.0.0) Note : The background isolate can be killed by the OS after around 40 seconds.
What do u mean with this?? I need something to let the app run in background for maybe hours!! Is it possible?
Hi everyone, sorry for the delay. I have published version 0.2.5 to fix this issue.
To registering plugis please see example: https://github.com/ekasetiawans/flutter_background_service/blob/master/packages/flutter_background_service/example/ios/Runner/AppDelegate.swift
Note that, only plugins that doesn't require UI allowed. If you wish to use shared_preferences or any other plugins that implements Dart plugin registration have a look : https://github.com/flutter/flutter/issues/98591 https://github.com/flutter/flutter/issues/98473
Thank you very much @ekasetiawans , now it works fine!!!! One last thing: i don't know why when i call stopBackgroundService(), the red banner on ios home is still there. Do you have any idea?
` FlutterBackgroundService().sendData( {"action": "stopService"}, );
if (event["action"] == "stopService") { TfliteAudio.stopAudioRecognition(); final json = RecognizerController.to.endReg(); FlutterBackgroundService().sendData( {"isStopped": json}, ); await Future.delayed(const Duration(milliseconds: 1000), () {}); FlutterBackgroundService().stopBackgroundService(); } `
Hi guys i got the same Problem on Android running Version 0.2.6 . I want to use porcupine_flutter https://pub.dev/packages/porcupine_flutter/versions/2.0.1 while app is in Background but when i try to run it there are some implementations not found
======== Exception caught by services library ======================================================
The following MissingPluginException was thrown while activating platform stream on channel flutter_voice_processor_events:
MissingPluginException(No implementation found for method listen on channel flutter_voice_processor_events)
When the exception was thrown, this was the stack:
#0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:175:7)
<asynchronous suspension>
#1 EventChannel.receiveBroadcastStream.<anonymous closure> (package:flutter/src/services/platform_channel.dart:516:9)
<asynchronous suspension>
@ekasetiawans The link to register the plugin is broken.
@TimeLord2010 I have updated the link.