Upgrade to Pro — share decks privately, control downloads, hide ads and more …

20190726 Background App Refresh Taskがやってきた

20190726 Background App Refresh Taskがやってきた

Kei Ito

July 26, 2019
Tweet

More Decks by Kei Ito

Other Decks in Programming

Transcript

  1. λεΫͷ౤ೖ func applicationDidEnterBackground(_ application: UIApplication) { scheduleAppRefresh() } func scheduleAppRefresh()

    { let request = BGAppRefreshTaskRequest(identifier: "XXX") request.earliestBeginDate = Date(timeIntervalSinceNow: 15 * 60) do { try BGTaskScheduler.shared.submit(request) } catch { print("Could not schedule app refresh: \(error)") } }
  2. λεΫͷ࣮ߦ func handleAppRefresh(task: BGAppRefreshTask) { // ඞཁ͕͋Ε͹࠶౤ೖ scheduleAppRefresh() task.expirationHandler =

    { // ࣮ߦظݶ͕੾Εͨͱ͖ͷΩϟϯηϧॲཧ } // do something // λεΫ׬ྃ task.setTaskCompleted(success: true) }