@@ -46,7 +46,10 @@ class BackgroundWorker {
4646 let flutterPluginRegistrantCallback : FlutterPluginRegistrantCallback ?
4747 let inputData : [ String : Any ] ?
4848
49- init ( mode: BackgroundMode , inputData: [ String : Any ] ? , flutterPluginRegistrantCallback: FlutterPluginRegistrantCallback ? ) {
49+ init (
50+ mode: BackgroundMode , inputData: [ String : Any ] ? ,
51+ flutterPluginRegistrantCallback: FlutterPluginRegistrantCallback ?
52+ ) {
5053 backgroundMode = mode
5154 self . inputData = inputData
5255 self . flutterPluginRegistrantCallback = flutterPluginRegistrantCallback
@@ -55,18 +58,21 @@ class BackgroundWorker {
5558 private struct BackgroundChannel {
5659 static let name = " \( SwiftWorkmanagerPlugin . identifier) /background_channel_work_manager "
5760 static let initialized = " backgroundChannelInitialized "
58- static let onResultSendCommand = " backgroundChannelInitialized "
61+ static let onResultSendCommand = " onResultSend "
5962 }
6063
6164 /// The result is discardable due to how [BackgroundTaskOperation] works.
6265 @discardableResult
63- func performBackgroundRequest( _ completionHandler: @escaping ( UIBackgroundFetchResult ) -> Void ) -> Bool {
66+ func performBackgroundRequest( _ completionHandler: @escaping ( UIBackgroundFetchResult ) -> Void )
67+ -> Bool
68+ {
6469 guard let callbackHandle = UserDefaultsHelper . getStoredCallbackHandle ( ) ,
65- let flutterCallbackInformation = FlutterCallbackCache . lookupCallbackInformation ( callbackHandle)
66- else {
67- logError ( " [ \( String ( describing: self ) ) ] \( WMPError . workmanagerNotInitialized. message) " )
68- completionHandler ( . failed)
69- return false
70+ let flutterCallbackInformation = FlutterCallbackCache . lookupCallbackInformation (
71+ callbackHandle)
72+ else {
73+ logError ( " [ \( String ( describing: self ) ) ] \( WMPError . workmanagerNotInitialized. message) " )
74+ completionHandler ( . failed)
75+ return false
7076 }
7177
7278 let taskSessionStart = Date ( )
@@ -105,7 +111,7 @@ class BackgroundWorker {
105111 backgroundMethodChannel? . setMethodCallHandler { call, result in
106112 switch call. method {
107113 case BackgroundChannel . initialized:
108- result ( true ) // Agree to Flutter's method invocation
114+ result ( true ) // Agree to Flutter's method invocation
109115 var arguments : [ String : Any ] = self . backgroundMode. onResultSendArguments
110116 if let inputData = self . inputData {
111117 arguments [ " dev.fluttercommunity.workmanager.INPUT_DATA " ] = inputData
@@ -117,9 +123,12 @@ class BackgroundWorker {
117123 result: { flutterResult in
118124 cleanupFlutterResources ( )
119125 let taskSessionCompleter = Date ( )
120- let result : UIBackgroundFetchResult = ( flutterResult as? Bool ?? false ) ? . newData : . failed
126+ let result : UIBackgroundFetchResult =
127+ ( flutterResult as? Bool ?? false ) ? . newData : . failed
121128 let taskDuration = taskSessionCompleter. timeIntervalSince ( taskSessionStart)
122- logInfo ( " [ \( String ( describing: self ) ) ] \( #function) -> performBackgroundRequest. \( result) (finished in \( taskDuration. formatToSeconds ( ) ) ) " )
129+ logInfo (
130+ " [ \( String ( describing: self ) ) ] \( #function) -> performBackgroundRequest. \( result) (finished in \( taskDuration. formatToSeconds ( ) ) ) "
131+ )
123132
124133 debugHelper. showCompletedFetchNotification (
125134 completedDate: taskSessionCompleter,
0 commit comments