Hi everyone,
I am trying to send a request to my server in my watch application when HKObserverQuery is triggered. This is working fine when my app is in foreground however the request is not sending when the app manually terminated or in background. HKObserverQuery works fine and triggered in these cases however the request is not sending. I researched about URLSessionConfiguration.background and background sessions but I could not figure it out. I don't want to download or upload a file, I just want to send a simple request when HKObserverQuery is triggered.
Can you show me to a path way to make it possible?
I am trying to test my watch app with my iPhone, I am assuming the behavior of these scenarios might be same in both device, am I correct?
let urlsession = URLSession(configuration: URLSessionConfiguration.background(withIdentifier: "enablement"), delegate: self, delegateQueue: nil)
let dataTask = urlsession.dataTask(with: urlRequest)
dataTask.resume()
As shown in the code snippet, I tried to set background configuration to my URLSession.
I enabled background fetch in background modes.
Apple documentation says, dataTask can not run in background -> https://developer.apple.com/documentation/foundation/urlsessiontask However I don't want to perform a long running task such as downloading or uploading.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hello. I have implemented background delivery for detecting changes in health kit with HKObserverQuery. It works well, I am reading changes. And I am sending this changes to an https endpoint with using an URLSession.shared.dataTask inside the HKObserverQuery callback while my app is terminated. I have several questions about this:
Is starting a URLSession.shared.dataTask inside HKObserverQuery callback when app is terminated is correct way to do it?
I am calling HKObserverQuery completion handler whatever dataTask returned success or failure but I am wondering what if the network connection is low and this dataTask response could not received in 2-3 seconds. I have read background deliveries should take 1-2 seconds. Should I use an URL session with background configuration for sending those HTTPS requests? If so, should I use download task or upload task (they don't fit my requirements I am sending a simple json)?
Hello. I have implemented background delivery for detecting changes in health kit with HKObserverQuery. It works well, I am reading changes. And I am sending this changes to an https endpoint with using an URLSession.shared.dataTask inside the HKObserverQuery callback while my app is terminated. I have several questions about this:
Is starting a URLSession.shared.dataTask inside HKObserverQuery callback is correct way to do it?
I am calling HKObserverQuery completion handler whatever dataTask returned success or failure but I am wondering what if the network connection is low and this dataTask response could not received in 2-3 seconds. I have read HealthKit background deliveries should take 1-2 seconds.
Should I use background task somehow for sending those HTTPS requests?