Skip to content

Commit

Permalink
feat: Support iOS 12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev-hwang committed Nov 1, 2024
1 parent c3f2430 commit 74a4522
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 3 additions & 3 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@
DEVELOPMENT_TEAM = 2BHAXN696Y;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -491,7 +491,7 @@
DEVELOPMENT_TEAM = 2BHAXN696Y;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -515,7 +515,7 @@
DEVELOPMENT_TEAM = 2BHAXN696Y;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
18 changes: 16 additions & 2 deletions ios/Classes/SwiftFlutterForegroundTaskPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,22 @@ public class SwiftFlutterForegroundTaskPlugin: NSObject, FlutterPlugin {

// ================== App Lifecycle ===================
public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [AnyHashable : Any] = [:]) -> Bool {
SwiftFlutterForegroundTaskPlugin.registerAppRefresh()
UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum)
if #available(iOS 13.0, *) {
SwiftFlutterForegroundTaskPlugin.registerAppRefresh()
}
return true
}

public func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) -> Bool {
completionHandler(.newData)
return true
}

public func applicationDidEnterBackground(_ application: UIApplication) {
SwiftFlutterForegroundTaskPlugin.scheduleAppRefresh()
if #available(iOS 13.0, *) {
SwiftFlutterForegroundTaskPlugin.scheduleAppRefresh()
}
}

public func applicationWillTerminate(_ application: UIApplication) {
Expand Down Expand Up @@ -123,12 +133,14 @@ public class SwiftFlutterForegroundTaskPlugin: NSObject, FlutterPlugin {
// ============== Background App Refresh ==============
public static var refreshIdentifier: String = "com.pravera.flutter_foreground_task.refresh"

@available(iOS 13.0, *)
private static func registerAppRefresh() {
BGTaskScheduler.shared.register(forTaskWithIdentifier: refreshIdentifier, using: nil) { task in
handleAppRefresh(task: task as! BGAppRefreshTask)
}
}

@available(iOS 13.0, *)
private static func scheduleAppRefresh() {
let request = BGAppRefreshTaskRequest(identifier: refreshIdentifier)
request.earliestBeginDate = Date(timeIntervalSinceNow: 15 * 60)
Expand All @@ -140,10 +152,12 @@ public class SwiftFlutterForegroundTaskPlugin: NSObject, FlutterPlugin {
}
}

@available(iOS 13.0, *)
private static func cancelAppRefresh() {
BGTaskScheduler.shared.cancel(taskRequestWithIdentifier: refreshIdentifier)
}

@available(iOS 13.0, *)
private static func handleAppRefresh(task: BGAppRefreshTask) {
let queue = OperationQueue()
let operation = AppRefreshOperation()
Expand Down

0 comments on commit 74a4522

Please sign in to comment.