Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
もう怖くないバックグラウンド処理 Background Tasks のすべて - Hakoda...
Search
Kanta Oikawa
February 22, 2026
Technology
450
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
もう怖くないバックグラウンド処理 Background Tasks のすべて - Hakodate.swift #1
Hakodate.swift #1 LT
Kanta Oikawa
February 22, 2026
More Decks by Kanta Oikawa
See All by Kanta Oikawa
2027年のMetricKit
kantacky
0
57
はじめてのCoreSpotlight
kantacky
0
120
ヘッドジェスチャを検知して Vibe Cooking - iOSDC Japan 2025
kantacky
0
660
Other Decks in Technology
See All in Technology
Genie Codeハンズオン応用編
taka_aki
0
120
20260804_Q4AzureUpdateBite_FabricDataAgentの精度を高める設計.pdf
matayuuu
1
150
小粒でもパワフルなJS Runtime Antjsについて
comamoca
0
100
自宅NWにISR4331を導入してみた話
okaits
0
110
Bits Agent Builder の⼊⾨と活⽤事例
nulabinc
PRO
0
200
ガバメント AI 源内を地方自治体は活用できるのか可能性と課題、期待について
takeda_h
2
450
FORENSIA: ローカルLLMフォレンジックハーネス
sumeshi
2
420
トヨタ⽣産⽅式(TPS)⼊⾨
recruitengineers
PRO
3
1k
モダンフロントエンド 開発研修
recruitengineers
PRO
4
790
PLATEAU で バーチャル花火大会
tatsuya1970
0
170
【AG-UI × A2UI × MCP Apps】Generative UIをやさしく解説する
nrinetcom
PRO
1
140
What's new in Go 1.27?
ciarana
0
260
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
247
13k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
210
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.5k
A Soul's Torment
seathinner
6
3.4k
Product Roadmaps are Hard
iamctodd
55
12k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
My Coaching Mixtape
mlcsv
0
250
Balancing Empowerment & Direction
lara
6
1.2k
Raft: Consensus for Rubyists
vanstee
141
7.6k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
Exploring anti-patterns in Rails
aemeredith
3
470
Transcript
Kanta Oikawa - 2026/02/22 ͏ා͘ͳ͍όοΫάϥϯυॲཧ Background Tasks ͷͯ͢ Hakodate.swift #1
LT
όοΫάϥϯυॲཧා͍ɺ͚Ͳେࣄ • iOSͷόοΫάϥϯυॲཧ੍͕ଟͯ͘େมͦ͏ • σόοά͕େมͦ͏ • ͰɺϢʔβʔମݧΛ্ͤ͞ΔͨΊʹආ͚ΒΕͳ͍͜ͱ • ۩ମతͳ੍ =
όοΫάϥϯυॲཧΛ࣮ߦ͢Δํ๏ • σόοάͷํ๏ • ͞Βͬͱ5Ͱ… 2
3
4
5
6
όοΫάϥϯυॲཧͷछྨͱํ๏ • Background ͰॲཧΛ։࢝͢Δ • App Refresh (BGAppRefreshTask) • Background
Push Noti fi cation • Processing (BGProcessingTask) • Foreground Ͱ։࢝ͨ͠ॲཧΛ Background Ͱܧଓ͢Δ • UIApplication / beginBackgroundTask(expirationHandler:) • BGContinuedProcessingTask (26+) 7
Background ͰॲཧΛ։࢝͢Δ App Refresh (BGAppRefreshTask) • e.g. גՁΞϓϦͰ࠷৽ͷגՁΛऔಘ • සൟʹΞΫηε͢ΔσʔλΛ࠷৽ͷঢ়ଶʹอͭ
• ࣮ߦλΠϛϯάΞϓϦͷ༻ύλʔϯʹԠͯ͡γεςϜ͕ܾఆ • "࣍ճ࣮ߦ·Ͱͷ࠷খ࣌ؒ" ͷΈίϯτϩʔϧՄೳ 8
Background ͰॲཧΛ։࢝͢Δ Background Push Noti fi cation • e.g. χϡʔεΞϓϦͷใهࣄ
• ཁ͢Δʹ Remote Push Noti fi cation • Push ϕʔεͰσʔλΛߋ৽ App Refresh Fetch ϕʔεͰσʔλΛߋ৽ • Push Noti fi cation Λड͚औͬͨޙͷॲཧ͕ଈ࣮࣌ߦ͞ΕΔอূͳ͍ 9
Background ͰॲཧΛ։࢝͢Δ Processing (BGProcessingTask) • e.g. σʔλϕʔεͷཧ • Ϣʔβʔ͕σόΠεΛ༻͍ͯ͠ͳ͍ؒʹ࣮ߦ͞ΕΔ •
Ϣʔβʔ͕σόΠεͷ༻Λ࢝ΊΔͱఀࢭ͞ΕΔ • ͔͔Δॲཧ࣮ߦͰ͖Δ͕ɺγεςϜʹΑΓதஅ͞ΕΔՄೳੑ͕͋Δ • ωοτϫʔΫଓঢ়ଶɺిݯଓঢ়ଶΛ࣮ߦ݅ͱͯ͠ࢦఆͰ͖Δ 10
Foreground Ͱ։࢝ͨ͠ॲཧΛ Background Ͱܧଓ͢Δ UIApplication / beginBackgroundTask(expirationHandler:) • e.g. ঢ়ଶͷมߋ,
σʔλϕʔεͷஅ • γεςϜ͕։࢝ͨ͠ॲཧΛɺ BackgroundʹભҠͯ͠ܧଓͯྃͤ͠͞Δ 11
Foreground Ͱ։࢝ͨ͠ॲཧΛ Background Ͱܧଓ͢Δ BGContinuedProcessingTask (26+) • e.g. InstagramͷετʔϦʔΛߘ •
Ϣʔβʔ͕։࢝ͨ͠ॲཧΛBackgroundʹભҠͯ͠ܧଓͯྃͤ͠͞Δ • ਐḿ͕Live ActivityͰදࣔ͞ΕΔ 12
Background Tasks ͷϑϩʔνϟʔτ 13
όοΫάϥϯυॲཧΛ࣮ߦ Background Modes Λ༗ޮԽ 14
όοΫάϥϯυॲཧΛ࣮ߦ Task ID Λ Info.plist ʹొ 15
όοΫάϥϯυॲཧΛ࣮ߦ (App Refresh, Processing) Task ID Λࢦఆͯ͠λεΫΛεέδϡʔϧ private func scheduleAppRefresh()
{ let request = BGAppRefreshTaskRequest(identifier: appRefreshTaskIdentifier) request.earliestBeginDate = Date(timeIntervalSinceNow: 15 * 60) do { try BGTaskScheduler.shared.submit(request) print("Scheduled app refresh successfully") } catch { print("Failed to schedule app refresh: \(error)") } } 16
App Refresh ͱ Processing Λσόοά 1. Xcode Ͱ Run Destination
ʹ࣮ػΛબ 2. Run ͯ͠λεΫΛεέδϡʔϧ 3. Foreground Ͱ Pause program execution ϘλϯΛԡ͢ 4. Home Screen ʹΔͳͲͯ͠ Background ʹભҠͤ͞Δ 5. LLDBͰҎԼΛ࣮ߦʢൃՐ͍ͤͨ͞λεΫͷTask IDΛࢦఆ͢Δʣ e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdenti fi er:@"com.kantacky.BackgroundTasksSample .refresh"] 17
࣮ࡍʹͬͯΈͨ ࣮ • 2/20·Ͱͷ1िؒ͘Β͍Ͱ Vibe Coding ͯ͠৹ࠪʹఏग़ͨ͠ΞϓϦ • RSS ϑΟʔυϦʔμʔ
• App RefreshͰϑΟʔυΛFetchͯ͠৽ணهࣄΛϩʔΧϧ௨ 18
࣮ࡍʹͬͯΈͨ ͱղܾࡦ • ӡΑ۪͘ʹ࣮ߦ͞Εͯɺ࣍ճ࣮ߦ·Ͱͷ࠷খ࣌ؒ͝ͱʹ௨͕དྷͯ͏͍͟ • ࣍ճ࣮ߦ·Ͱͷ࠷খ࣌ؒΛେ͖͘͢Δɺ௨ରΛߜΔ • Background Push Noti
fi cation Λ͏ • αʔόʔͰϑΟʔυΛFetchͯ͠ɺ৽ணهࣄΛϦϞʔτ௨ • ௨ΛఘΊͯɺApp RefreshͰϑΟʔυΛ࠷৽ͷঢ়ଶʹอ͚ͭͩʹͱͲΊΔ 19
Materials https://kantacky.com/hakodate-swift-1 • εϥΠυ • https://speakerdeck.com/kantacky/hakodate-swift-1 • App RefreshΛ࣮ͨ͠αϯϓϧίʔυ •
https://github.com/kantacky/background-tasks-ios 20
Kanta Oikawa • ެཱͩͯ͜ະདྷେֶ M1 • Έͳ͞ΜɺവؗʹΑ͏ͦ͜ʂ • ͥͻຬ٤͍͍ͯͬͯͩ͘͠͞ 21