@@ -85,12 +85,22 @@ public class SwiftFlutterForegroundTaskPlugin: NSObject, FlutterPlugin {
8585
8686 // ================== App Lifecycle ===================
8787 public func application( _ application: UIApplication , didFinishLaunchingWithOptions launchOptions: [ AnyHashable : Any ] = [ : ] ) -> Bool {
88- SwiftFlutterForegroundTaskPlugin . registerAppRefresh ( )
88+ UIApplication . shared. setMinimumBackgroundFetchInterval ( UIApplication . backgroundFetchIntervalMinimum)
89+ if #available( iOS 13 . 0 , * ) {
90+ SwiftFlutterForegroundTaskPlugin . registerAppRefresh ( )
91+ }
92+ return true
93+ }
94+
95+ public func application( _ application: UIApplication , performFetchWithCompletionHandler completionHandler: @escaping ( UIBackgroundFetchResult ) -> Void ) -> Bool {
96+ completionHandler ( . newData)
8997 return true
9098 }
9199
92100 public func applicationDidEnterBackground( _ application: UIApplication ) {
93- SwiftFlutterForegroundTaskPlugin . scheduleAppRefresh ( )
101+ if #available( iOS 13 . 0 , * ) {
102+ SwiftFlutterForegroundTaskPlugin . scheduleAppRefresh ( )
103+ }
94104 }
95105
96106 public func applicationWillTerminate( _ application: UIApplication ) {
@@ -123,12 +133,14 @@ public class SwiftFlutterForegroundTaskPlugin: NSObject, FlutterPlugin {
123133 // ============== Background App Refresh ==============
124134 public static var refreshIdentifier : String = " com.pravera.flutter_foreground_task.refresh "
125135
136+ @available ( iOS 13 . 0 , * )
126137 private static func registerAppRefresh( ) {
127138 BGTaskScheduler . shared. register ( forTaskWithIdentifier: refreshIdentifier, using: nil ) { task in
128139 handleAppRefresh ( task: task as! BGAppRefreshTask )
129140 }
130141 }
131142
143+ @available ( iOS 13 . 0 , * )
132144 private static func scheduleAppRefresh( ) {
133145 let request = BGAppRefreshTaskRequest ( identifier: refreshIdentifier)
134146 request. earliestBeginDate = Date ( timeIntervalSinceNow: 15 * 60 )
@@ -140,10 +152,12 @@ public class SwiftFlutterForegroundTaskPlugin: NSObject, FlutterPlugin {
140152 }
141153 }
142154
155+ @available ( iOS 13 . 0 , * )
143156 private static func cancelAppRefresh( ) {
144157 BGTaskScheduler . shared. cancel ( taskRequestWithIdentifier: refreshIdentifier)
145158 }
146159
160+ @available ( iOS 13 . 0 , * )
147161 private static func handleAppRefresh( task: BGAppRefreshTask ) {
148162 let queue = OperationQueue ( )
149163 let operation = AppRefreshOperation ( )
0 commit comments