Background App Refresh Tasksを実装したく、こちらの動画を参考に作ったのですがエラーが発生してしまいます。
※IDとアプリ名は伏せています。
コード
Swift
1@UIApplicationMain 2class AppDelegate: UIResponder, UIApplicationDelegate { 3 4 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 5 // Override point for customization after application launch. 6 BGTaskScheduler.shared.register(forTaskWithIdentifier: "(ID)", using: nil) { task in 7 self.handleAppRefresh(task: task as! BGAppRefreshTask) 8 } 9 return true 10 } 11 12 private func scheduleAppRefresh(){ 13 let request = BGAppRefreshTaskRequest(identifier: "(ID)") 14 request.earliestBeginDate = Date(timeIntervalSinceNow: 15 * 60) 15 16 do{ 17 try BGTaskScheduler.shared.submit(request) 18 }catch{ 19 print("Could not schedule app refresh: (error)") 20 } 21 } 22 23 private func handleAppRefresh(task: BGAppRefreshTask){ 24 print("handleAppRefresh") 25 scheduleAppRefresh() 26 27 let queue = OperationQueue() 28 queue.maxConcurrentOperationCount = 1 29 task.expirationHandler = { 30 queue.cancelAllOperations() 31 } 32 33 let operation = BackgroundOperation(data: data) 34 operation.completionBlock = { 35 task.setTaskCompleted(success: operation.isFinished) 36 } 37 queue.addOperation(operation) 38 } 39 40 func applicationDidEnterBackground(_ application: UIApplication) { 41 scheduleAppRefresh() 42 } 43}
エラー内容
(lldb) e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"(ID)"] 2020-07-12 11:29:02.361967+0900 (APP)[16651:1009468] Simulating launch for task with identifier (ID) 2020-07-12 11:29:05.332996+0900 (APP)[16651:1009665] No task request with identifier (ID) has been scheduled
あなたの回答
tips
プレビュー