https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
e

Elelan Vickneshvararajah (Elelan)

10/18/2023, 5:42 PM
Hello guys! I have a doubt about implementing background tasks in kmm. In android we've used workmanager so far. How can we implement background tasks in kmm apps?
p

Pablichjenkov

10/18/2023, 5:56 PM
Apple has a framework called BackgroundTask. You may find some similarities with Android Work Manager and create a wrapper layer around that
c

Casey Brooks

10/18/2023, 6:14 PM
I actually just started working on a library to help with this. Currently only have a POC for in-process schedules and WorkManager, but iOS support is something I will be looking into as well. Still an early prototype, but feedback and/or contributions (especially for iOS) would be greatly appreciated! https://kotlinlang.slack.com/archives/C03GTEJ9Y3E/p1697648634102369 There are several KMP libraries I’ve seen that do “background tasks”, but from what I can tell, they all are just some form of “background threads” and don’t support persistent work like WorkManager.
🔥 2
a

Aditya Kurkure

10/18/2023, 6:59 PM
BackgroundTask only works for iOS 13 and above though, so if you want to support earlier versions you'd want to use this.
p

Pablichjenkov

10/18/2023, 7:10 PM
Isn't iOS 13 a bit outdated? How many existing devices are running that OS version. It is around 4 years old and the average phone last no more than 2 years. Especially iOS, that has a better new device adoption rate than Android.
c

Casey Brooks

10/18/2023, 8:05 PM
Yeah, looks like 97% of iPhones are running iOS 13 or higher (source). Unless you have very specific needs to run on very old phones, a requirement of iOS 13 seems perfectly reasonable
2
a

Aditya Kurkure

10/18/2023, 8:30 PM
interesting, I've had to work with apps targeting iOS 12 before and it was a bit of a hassle that's why I thought of mentioning it.
p

Pablichjenkov

10/18/2023, 8:40 PM
Is a valid point, it depends on the project and the type of user you target obviously. Is a balance between ease of development using a newer API at the cost of losing a few users.
14 Views