-
First of all you need add "Backgoround fetch", "Background processing" capabilities in your project (Runner->Singin & Capabilities->Background Modes)
-
Then in main Info.plist Permitted background task scheduler identifiers add items with identifiers:
- For refresh tasks - com.vergo.iosBackground.refresh.YOUR_TASK_NAME
- For processing tasks - com.vergo.iosBackground.ProcessingTask.YOUR_TASK_NAME
-
Add the following code to your project Runner->AppDelegate.swift :
import background- after import Flutterlet bgRefreshTasksIdentifiers = ["com.vergo.iosBackground.refresh.testRefresh.YOUR_TASK_NAME"] let bgProcessingTasksIdentifiers = ["com.vergo.iosBackground.ProcessingTask.testProcessing.YOUR_TASK_NAME"] BackgroundPlugin().saveIdentifires(bgProcessingTasksIdentifiers: bgProcessingTasksIdentifiers, bgRefreshTasksIdentifiers: bgRefreshTasksIdentifiers)Before GeneratedPluginRegistrant.register(with: self) line
You can add as much as you want tasks, BUT TWO IMPORTANT THINGS:
- Identifiers witch you add in AppDelegate must match with identifiers in Info.plist
- YOUR_TASK_NAME - mast match with task names, witch you create in your code
- You need add breakpoint after
try BGTaskScheduler.shared.submit(request)line - Then after your app has been paused execute the following comand in Xcode command line
e -l objc -- (void)[[BGTaskScheduler sharedScheduler _simulateLaunchForTaskWithIdentifier:@"YOUR_TASK_IDENTIFIER"]
- Resume back your app
- Well done, your task should be executed
This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.
For help getting started with Flutter development, view the online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.