TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: Continue API-Request when Apple Watch is in sleep mode SwiftUI

Forums > SwiftUI

@Kdkwn  

I am working on a standalone Apple Watch App with SwiftUI. My problem is, that I am starting a API-Request on a button click. But when the user is moving his hand down, the display turns off or is going into always-on mode. My API request also aborts. Is there a way to continue executing the request even if the Apple Watch is in this state?

2      

This is difficult. Apple allows for watchOS only certain background modes which are described here: https://developer.apple.com/documentation/watchkit/background_execution/enabling_background_sessions

Depending in which category your app belongs it could be possible you can utilise them. This means that your app doesn't go into background if you lower your wrist. But your app will be suspended when there is no activity in a specific time frame. For example, when there is no activity in a workout session some point in the future the workout session will be canceled.

If your app doesn't belong to one of these categories it could be possible your app could be rejected in app review. If you use it for your own purpose in development mode it doesn't matter, though.

You can try remote notifications as well. So your app sends only a request (which should be fast) and the response is send via notification. But I have no experience with this. https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app

2      

@Kdkwn  

Thanks I will have a look into that :)

2      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.