HomeiOS Developmentswift - iOS BGTaskScheduler not working

swift – iOS BGTaskScheduler not working


I’m engaged on an App which shields some purposes, and when person achieves specific step rely, it unshields these apps.

My inspiration is that this under app. (Social Limits)
https://apps.apple.com/au/app/social-limits/id6471964510

My essential query is concerning BGTaskScheduler, Which isn’t working as meant. Its essential goal is to run periodically and verify if person has achieved sure steps and unshields the app even when app is terminated or in background.

I’ve experimented with Social Limits app and I do know that it makes use of Background App Refresh to unshield the apps. (Examined this by revoking the permission and sees if it unblocks the app however it doesn’t with out this permission).

How can I obtain what Social restrict has achieved.

That is my code:

  BGTaskScheduler.shared.register(forTaskWithIdentifier: refreshTaskIdentifier, utilizing: nil) { job in
        self.handleAppRefresh(job: job as! BGAppRefreshTask)
    }

I name a operate to set the scheduler:

 scheduleAppRefresh()


personal func scheduleAppRefresh() {
    //     MARK: - e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"com.check.socialLimit.refreshTask"]
 //        BGTaskScheduler.shared.cancel(taskRequestWithIdentifier: refreshTaskIdentifier)
    BGTaskScheduler.shared.getPendingTaskRequests { requests in
        print("(requests.rely) BGTask Pending")
        
        guard requests.isEmpty else { return }
        
        let request = BGAppRefreshTaskRequest(identifier: self.refreshTaskIdentifier)
        request.earliestBeginDate = Date(timeIntervalSinceNow: 15 * 60) // Earliest 15 minutes later
        do {
            strive BGTaskScheduler.shared.submit(request)
            print("TASK SCHEDULE")
        } catch {
            print("Couldn't schedule app refresh: (error)")
        }
    }
}

That is my precise work dealing with operate:

    personal func handleAppRefresh(job: BGAppRefreshTask) {
    scheduleAppRefresh() // Schedule the subsequent refresh
    
    let queue = OperationQueue()
    queue.maxConcurrentOperationCount = 1
    
    let operation = BackgroundRefreshOperation()
    
    job.expirationHandler = {
        queue.cancelAllOperations()
    }
    
    operation.completionBlock = {
        job.setTaskCompleted(success: !operation.isCancelled)
    }
    
    queue.addOperation(operation)
}

The issue is it runs when debugging with command
e -l objc — (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@”com.check.socialLimit.refreshTask”]

however would not work when app is on testFlight. I’ve even waited for twenty-four hours.

*** After 3 days of testing it ran simply 1 time.***

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments