flutter_background_service
flutter_background_service copied to clipboard
How can I run this plugin only for iOS?
I have an app that runs on Android and iOS. How can I run this plugin only in iOS?
This is not working, it runs in Android too:
void main() async{
WidgetsFlutterBinding.ensureInitialized();
if(Platform.isIOS){
print('START BACKGROUND SERVICE');
await initializeService();
}
runApp(App(title: Config.appName, navigatorKey: navigatorKey));
}
Future<void> initializeService() async {
final service = FlutterBackgroundService();
await service.configure(
androidConfiguration: AndroidConfiguration(
// this will executed when app is in foreground or background in separated isolate
onStart: (){},
// auto start service
autoStart: true,
isForegroundMode: false,
),
iosConfiguration: IosConfiguration(
// auto start service
autoStart: true,
// 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,
),
);
}
// to ensure this executed
// run app from xcode, then from xcode menu, select Simulate Background Fetch
void onIosBackground() async{
WidgetsFlutterBinding.ensureInitialized();
//code
}
void onStart() {
WidgetsFlutterBinding.ensureInitialized();
final service = FlutterBackgroundService();
//code
}