This commit is contained in:
Bilal
2024-09-23 09:20:29 +05:30
parent 15681d2402
commit 8ffad16ddb
3 changed files with 118 additions and 4 deletions

View File

@@ -77,19 +77,19 @@
<CommandLineArguments>
<CommandLineArgument
argument = "-FIRAnalyticsDebugEnabled"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-FIRDebugEnabled"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-FIRDebugDisabled"
isEnabled = "NO">
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-FIRAnalyticsDebugDisabled"
isEnabled = "NO">
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
<EnvironmentVariables>

View File

@@ -2,6 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>com.woka.refresh</string>
</array>
<key>API_KEY_ID</key>
<string>$(API_KEY_ID)</string>
<key>API_KEY_PASS</key>
@@ -44,6 +48,8 @@
<array>
<string>audio</string>
<string>remote-notification</string>
<string>fetch</string>
<string>processing</string>
</array>
</dict>
</plist>

View File

@@ -12,6 +12,7 @@ import JWPlayerKit
import Firebase
import GoogleMobileAds
import OneSignalFramework
import BackgroundTasks
let appDelegate = UIApplication.shared.delegate as! AppDelegate
@@ -20,7 +21,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var deviceOrientation = UIInterfaceOrientationMask.portrait
let taskID = "com.woka.refresh"
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return deviceOrientation
}
@@ -69,8 +72,45 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
//Configure JWPlayer Liscense
JWPlayerKitLicense.setLicenseKey("Lgok1t7H4PKY+M8FZqmCx54ibUF+NeCTn+xgd+/LVTaRdc+L")
// Register the background refresh task
// BGTaskScheduler.shared.register(forTaskWithIdentifier: taskID, using: nil) { task in
// // This block is called when the task is triggered
// guard let task = task as? BGAppRefreshTask else{return}
// self.handleTask(task: task)
// }
//
// scheduleTasks()
return true
}
// func scheduleTasks(){
// BGTaskScheduler.shared.getPendingTaskRequests { requests in
// print("Request :- ", requests.count)
//
// guard requests.isEmpty else{
// return
// }
//
// // submit task to be scheduled
// do{
// let newTask = BGAppRefreshTaskRequest(identifier: self.taskID)
// // Set when you want the task to run (optional)
// newTask.earliestBeginDate = Date(timeIntervalSinceNow: 15 * 60) // minutes * seconds ie. 1 min * 60 second, it ill trigger in 1 min.
// print("Task Scheduled.")
// try BGTaskScheduler.shared.submit(newTask)
// } catch{
// print("Issue with task")
// }
// }
//
// }
//
// func handleTask(task : BGAppRefreshTask){
// self.localNoti(body: "sad")
// task.setTaskCompleted(success: true)
// }
// MARK: UISceneSession Lifecycle
@@ -85,7 +125,75 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
func scheduleAppRefresh() {
let request = BGAppRefreshTaskRequest(identifier: taskID)
// Set when you want the task to run (optional)
request.earliestBeginDate = Date(timeIntervalSinceNow: 2 * 60) // 15 minutes from now
do {
try BGTaskScheduler.shared.submit(request)
print("Could not schedule app refresh scheduled")
} catch {
print("Could not schedule app refresh: \(error)")
}
}
func handleAppRefresh(task: BGAppRefreshTask) {
// Schedule a new refresh task
scheduleAppRefresh()
// Perform the background task (e.g., fetching data from a server)
let operationQueue = OperationQueue()
operationQueue.maxConcurrentOperationCount = 1
let fetchOperation = BlockOperation {
// Perform your background fetch task here (e.g., network call)
self.performBackgroundFetch { newData in
task.setTaskCompleted(success: newData)
}
}
task.expirationHandler = {
// Cancel the operation if it takes too long
operationQueue.cancelAllOperations()
}
operationQueue.addOperation(fetchOperation)
}
func performBackgroundFetch(completion: @escaping (Bool) -> Void) {
// Simulate a network call
DispatchQueue.global().asyncAfter(deadline: .now() + 5) {
// Perform your background work here
let newDataFetched = true // Assume data was fetched
completion(newDataFetched)
print("sdaasdasdasdas")
self.localNoti(body: newDataFetched ? "true" : "false")
}
}
func localNoti(body : String? = nil){
//creating the notification content
let content = UNMutableNotificationContent()
//adding title, subtitle, body and badge
content.title = "Your are out of Geofence, Battery testing"
content.subtitle = ""
content.body = body == nil ? "Please contact your Careperson" : body!
content.badge = 1
//getting the notification trigger
//it will be called after 5 seconds
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
//getting the notification request
let request = UNNotificationRequest(identifier: "SimplifiedIOSNotification", content: content, trigger: trigger)
//adding the notification to notification center
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
}
}
extension AppDelegate {