Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS package inside onStart() function throws "missing plugin implementation" exception #89

Closed
bobosette opened this issue Jan 22, 2022 · 24 comments

Comments

@bobosette
Copy link

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?

@ekasetiawans
Copy link
Owner

ekasetiawans commented Jan 22, 2022

can you provide flutter doctor output?

@bobosette
Copy link
Author

bobosette commented Jan 22, 2022 via email

@Habib-T4ULabs
Copy link

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)

@bobosette
Copy link
Author

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)

@ekasetiawans
Copy link
Owner

@bobosette have you call WidgetsFlutterBinding.ensureInitialized() in onStart() method?

@bobosette
Copy link
Author

Yes. I give you some code:

`
void main() async {
WidgetsFlutterBinding.ensureInitialized();
initializeService();
runApp(const MyApp());
}

void onIosBackground() {
WidgetsFlutterBinding.ensureInitialized();
}

Future initializeService() async {
final service = FlutterBackgroundService();
await service.configure(
androidConfiguration: AndroidConfiguration(
// this will executed when app is in foreground or background in separated isolate
onStart: onStart,

  // 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()

@ekasetiawans
Copy link
Owner

@Habib-T4ULabs
Copy link

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.

@ekasetiawans
Copy link
Owner

@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.

@Habib-T4ULabs
Copy link

@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.

@ekasetiawans
Copy link
Owner

@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.

@bobosette
Copy link
Author

bobosette commented Feb 3, 2022 via email

@Habib-T4ULabs
Copy link

Habib-T4ULabs commented Feb 3, 2022

@ekasetiawans can you please give me the right steps to fix it as your functions are no longer available in the new versions ?

@Habib-T4ULabs
Copy link

@ekasetiawans i forked the repository and tried what you proposed previously but still get the same error

@paraslamsong
Copy link

@Habib-T4ULabs
any progress?

@Habib-T4ULabs
Copy link

@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.

@bobosette
Copy link
Author

@Habib-T4ULabs what package?

@Habib-T4ULabs
Copy link

@bobosette I used this package (flutter_isolate 2.0.0)
Note : The background isolate can be killed by the OS after around 40 seconds.

@bobosette
Copy link
Author

What do u mean with this?? I need something to let the app run in background for maybe hours!! Is it possible?

@ekasetiawans
Copy link
Owner

ekasetiawans commented Feb 16, 2022

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 :
flutter/flutter#98591
flutter/flutter#98473

@bobosette
Copy link
Author

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();
}
`

@Nailik
Copy link

Nailik commented Feb 25, 2022

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>

@TimeLord2010
Copy link

@ekasetiawans The link to register the plugin is broken.

@ekasetiawans
Copy link
Owner

@TimeLord2010 I have updated the link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants