swift – iOS BGTaskScheduler not working

0
1
swift – iOS BGTaskScheduler not working


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

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

My most important query is concerning BGTaskScheduler, Which isn’t working as meant. Its most important objective is to run periodically and test if consumer 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 nevertheless 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 perform to set the scheduler:

 scheduleAppRefresh()


non-public func scheduleAppRefresh() {
    //     MARK: - e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"com.take a look at.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 perform:

    non-public func handleAppRefresh(job: BGAppRefreshTask) {
    scheduleAppRefresh() // Schedule the following 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.take a look at.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.***

LEAVE A REPLY

Please enter your comment!
Please enter your name here