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

20190726 Background App Refresh Taskがやってきた

Kei Ito
July 26, 2019

20190726 Background App Refresh Taskがやってきた

Kei Ito

July 26, 2019
Tweet

More Decks by Kei Ito

Other Decks in Programming

Transcript

  1. #BDLHSPVOE"QQ 3FGSFTI5BTL͕ ΍͖ͬͯͨ .PCJMF"DU04"," JUPL!ͦΒ͔ͥ

  2. JUPL!ͦΒ͔ͥ w ͍ͱ͏͚͍ʢJUPLʣ w ɹɹɹɹɹɹͷதͷਓʢʴ෭ۀˏ͸ͯͳʣ w ϞόΠϧΞϓϦΤϯδχΞ݉$&0 w IUUQTJUPLKQ IUUQTTPSBLB[FDPKQ

    !JUPLKQ
  3. ॴࡏ஍ɿژ౎ࢢதژ۠ ࣾһਓࣗ෼

  4. J04"OESPJENBD048JOEPXTαʔό ҰਓͰ΍ͬͯ·͢ʢσβΠϯҎ֎ʣ

  5. #BDLHSPVOE"QQ 3FGSFTI5BTL͕ ΍͖ͬͯͨ

  6. "EWBODFTJO"QQ #BDLHSPVOE&YFDVUJPO EFWFMPQFSBQQMFDPNWJEFPTQMBZXXED 88%$4FTTJPO

  7. J04

  8. #BDLHSPVOE5BTLT GSBNFXPSL

  9. None
  10. #BDLHSPVOE"QQ 3FGSFTI5BTL w ඵؒಈ͚Δ w ΞϓϦΛ࠷৽ͷঢ়ଶʹอͯΔ w CBDLHSPVOEGFUDIͷ"1*͸EFQSFDBUFE w NBD04͸چ"1*Ͱಈ͔ͳ͍͔ΒJ1BE04

     $BUBMZTU࢖͏ͳΒ͜ΕʹҠߦ͢΂͠
  11. #BDLHSPVOE1SPDFTTJOH 5BTL w ਺෼ಈ͚Δ w %#ͷϝϯςφϯεͱ͔ɺ.-ͷֶशͱ͔

  12. ४උ w DBQBCJMJUZˠCBDLHSPVOENPEFTˠ w CBDLHSPVOEGFUDI w CBDLHSPVOEQSPDFTTJOH w *OGPQMJTUˠ#(5BTL4DIFEVMFS1FSNJUUFE*EFOUJpFST w

    λεΫͷࣝผࢠΛྻڍ
  13. λεΫͷొ࿥ BGTaskScheduler.shared.register(forTaskWithIdentifier: "XXX", using: nil) { task in self.handleAppRefresh(task: task

    as! BGAppRefreshTask) }
  14. λεΫͷ౤ೖ 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)") } }
  15. λεΫͷ࣮ߦ func handleAppRefresh(task: BGAppRefreshTask) { // ඞཁ͕͋Ε͹࠶౤ೖ scheduleAppRefresh() task.expirationHandler =

    { // ࣮ߦظݶ͕੾Εͨͱ͖ͷΩϟϯηϧॲཧ } // do something // λεΫ׬ྃ task.setTaskCompleted(success: true) }
  16. ύϥϝʔλ w ڞ௨ w FBSMJFTU#FHJO%BUF w ԕ͗͢Δະདྷ͸ͩΊ w िؒҎ಺͘Β͍͕๬·͍͠ w

    ʮ࠷୹ʯͳͷͰ࣮ߦ͞ΕΔͱ͸ݶΒͳ͍
  17. ύϥϝʔλ w QSPDFTTJOHUBTL w SFRVJSFT/FUXPSL$POOFDUJWJUZ w SFRVJSFT&YUFSOBM1PXFS w $16Λ࢖͏࢓ࣄΛ͢Δ৔߹͸USVFʹ͓ͯ͜͠͏

  18. σόοά w σόοΨ͔ΒλεΫͷ࣮ߦ΍ظݶ੾ΕΛςετՄೳ IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOCBDLHSPVOEUBTLT TUBSUJOH@BOE@UFSNJOBUJOH@UBTLT@EVSJOH@EFWFMPQNFOU FMPCKD WPJE <<#(5BTL4DIFEVMFSTIBSFE4DIFEVMFS>a @TJNVMBUF-BVODI'PS5BTL8JUI*EFOUJpFS!999>

  19. #BDLHSPVOEΛ੐ͯ͠ ΑΓΑ͍ϢʔβମݧΛʂ