Post

Replies

Boosts

Views

Activity

Reply to HealthKit Background Delivery and URLSession.shared.dataTask
I read that thread and associated threads and watched WWDC19. As I see, you answered and explained background task very detailed in these threads. Really appreciated. However, instead of answering my questions, they raised more questions for me :). You wrote that "The UIApplication background task mechanism allows you to prevent your app from being suspended for short periods of time". In my case, the application is terminated and relaunched by HKObserverQuery. At this point I fetch new health informations and use standart session to send these changes to my server. So should I execute this normal session with the UIApplication background task while app relaunched with HKBackgroundDelivery? I am asking this question because UIApplication background task looks like in the documentation , it should used when app is in foreground and app closed by the user while some tasks are not completed then we should use UIApplication background task to complete these tasks. I looked to BGAppRefreshTask and it looks really fit to my case. However, WWDC19 mention that "the system learns usage patterns of the application and starts launching your app according to this pattern and this also means that an app that isn't used frequently may not launch as frequently as well." But I want to send these health data changes when they are detected by HKObserverQuery. Since my app is designed for people with disabilities, they are unlikely to open the application frequently. This makes the usage-pattern–based scheduling of BGAppRefreshTask unsuitable for my case. Also in the same video mentioned that "Ensure files are accessible while device is locked". In my case, health data are encrypted by Health Kit while the device is locked and HKObserverQuery doesn't trigger while the device is locked. I tried learn about BGHealthResearchTask but there is no detailed explanation about it. When we should use it? How can I consider my work as a research? How is it schedule the task? What are the requirements to use it? I also looked at BGAppProcessingTask . It says it should be used time-consuming and intensive work but my task is simple and doesn't require several minutes. I tried to make my question as clear as possible. As I mentioned above, thank you so much for your detailed answers. Whenever I see your name in a thread, it makes me happy because you always provide clear and detailed explanations.
1w
Reply to How to send a simple request when HKObserverQuery triggered in background?
@DTS Engineer Hello, thank you for reply. No, there isn't a limitation or reason to use background URLSession. I am able to send requests with following code snippet while app is suspended: let urlsession = URLSession(configuration: URLSessionConfiguration.background(withIdentifier: "enablement"), delegate: self, delegateQueue: nil) let dataTask = urlsession.downloadTask(with: urlRequest) dataTask.resume() However, when I use this background urlSession with dataTask instead of downloadTask, it's doesn't work. To sum up, I couldn't find a task type which suits to my operation. I don't want a download, upload or time consuming operation. Using download task works but doesn't seem like the proper way to it. If this is wrong way to do, can you explain to me the proper way?
Oct ’24