@@ -26,6 +26,10 @@ public class SwiftWorkmanagerPlugin: FlutterPluginAppLifeCycleDelegate {
2626 }
2727 }
2828
29+ struct CheckBackgroundRefreshPermission {
30+ static let name = " \( CheckBackgroundRefreshPermission . self) " . lowercasingFirst
31+ }
32+
2933 struct RegisterOneOffTask {
3034 static let name = " \( RegisterOneOffTask . self) " . lowercasingFirst
3135 enum Arguments : String {
@@ -144,7 +148,7 @@ public class SwiftWorkmanagerPlugin: FlutterPluginAppLifeCycleDelegate {
144148
145149 /// Immediately starts a one off task
146150 @available ( iOS 13 . 0 , * )
147- public static func startOneOffTask( identifier: String , taskIdentifier: UIBackgroundTaskIdentifier , inputData: String , delaySeconds: Int64 ) {
151+ public static func startOneOffTask( identifier: String , taskIdentifier: UIBackgroundTaskIdentifier , inputData: String , delaySeconds: Int64 ) {
148152 let operationQueue = OperationQueue ( )
149153 // Create an operation that performs the main part of the background task
150154 let operation = BackgroundTaskOperation (
@@ -267,6 +271,9 @@ extension SwiftWorkmanagerPlugin: FlutterPlugin {
267271 case ( ForegroundMethodChannel . Methods. Initialize. name, let . some( arguments) ) :
268272 initialize ( arguments: arguments, result: result)
269273 return
274+ case ( ForegroundMethodChannel . Methods. CheckBackgroundRefreshPermission. name, . some) :
275+ _ = checkBackgroundRefreshPermission ( result: result)
276+ return
270277 case ( ForegroundMethodChannel . Methods. RegisterOneOffTask. name, let . some( arguments) ) :
271278 registerOneOffTask ( arguments: arguments, result: result)
272279 return
@@ -325,6 +332,7 @@ extension SwiftWorkmanagerPlugin: FlutterPlugin {
325332 let inputData =
326333 arguments [ method. Arguments. inputData. rawValue] as? String
327334
335+
328336 taskIdentifier = UIApplication . shared. beginBackgroundTask ( withName: uniqueTaskIdentifier, expirationHandler: {
329337 // Mark the task as ended if time is expired, otherwise iOS might terminate and will throttle future executions
330338 UIApplication . shared. endBackgroundTask ( taskIdentifier)
@@ -395,8 +403,8 @@ extension SwiftWorkmanagerPlugin: FlutterPlugin {
395403 SwiftWorkmanagerPlugin . scheduleBackgroundProcessingTask (
396404 withIdentifier: uniqueTaskIdentifier,
397405 earliestBeginInSeconds: delaySeconds,
398- requiresNetworkConnectivity: requiresNetwork ,
399- requiresExternalPower: requiresCharging )
406+ requiresNetworkConnectivity: requiresCharging ,
407+ requiresExternalPower: requiresNetwork )
400408
401409 result ( true )
402410 return
@@ -492,4 +500,4 @@ extension SwiftWorkmanagerPlugin {
492500 return worker. performBackgroundRequest ( completionHandler)
493501 }
494502
495- }
503+ }
0 commit comments