Relative Content

Tag Archive for iosxcodeswiftuiwidgetkit

How to make a network request in an iOS Interactive Widget AppIntent that uses completion blocks

I have an interactive Widget for iOS 17+ that when a user taps in a Widget button, the AppIntent should contact the backend and perform an action, and retrieve a result, either success or failure. This response should update the widget accordingly.
The API:
The backend connection is made through an old Obj-C lib that deals with certificates, hashes, encryption, etc., and the API is using completion blocks. Migrating to async await is not an option in this case.
What have I tried:
Adapt the perform() function of the AppIntent to perform the network request, wait for the completion and return, using withCheckedThrowingContinuation to bridge between the completions and async await.