Posts

Post marked as solved
3 Replies
I'm trying to implement a refresh backgroundtask that is scheduled when receive data in Notification Service Extensionoverride func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { DispatchQueue.main.async { self.cancelAllPendingBGTask() let request = BGAppRefreshTaskRequest(identifier: “com.hanbiro.task.gps”) // Fetch no earlier than 0.5 minutes from now request.earliestBeginDate = nil do { try BGTaskScheduler.shared.submit(request) } catch { print("Could not schedule app refresh: \(error)")} } } }func cancelAllPendingBGTask() { BGTaskScheduler.shared.cancelAllTaskRequests() }I already updated UIBackgroundModes, BGTaskSchedulerPermittedIdentifiers. But when debug ontry BGTaskScheduler.shared.submit(request)bye -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"com.hanbiro.task.gps"]my handler method on main app does not run, and debugger prints messages:(lldb) e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"com.hanbiro.task.gps"] 2019-12-16 15:27:57.205297+0700 PushAlarmNotificationService[7785:990824] Simulating launch for task with identifier com.hanbiro.task.gps 2019-12-16 15:28:02.683175+0700 PushAlarmNotificationService[7785:991061] No task request with identifier com.haniro.task.gps has been scheduledSo have to put my handler method on extension if I want to schedule a task on extension? I want to put it (handler) on main app, is that OK?