Inactivity Timeouts & Async Completion Handlers

Avanish Rayankula
2 min readJun 19, 2021

Inactivity related timeouts are implemented in applications that contain confidential informtation. Think of your favorite banking app.

Problem

We wanted to make sure that the inactivity timeout was indeed getting extended upon user interaction to ensure that the completion/failure handlers for asynchronous operations were getting executed prior to a logout initiated due to inactivity.

Investigation

First part part of the investigation was to see if we were indeed increasing the timeout interval in our application when user interactions occurred. I was aware that this was happening, but wasn’t aware of how.

Upon browsing through the code, the approach we were using worked by intercepting sendEvent calls, in a subclass of UIApplication and dispatch the event further by calling [super sendEvent:event].

The asynchronous operations that we were worried about were not going to be a concern for the timeout scenario because the timeout window is currently large enough for the asynchronous operations to easily complete/fail.

A new problem

The reason execution of the failure handlers is important for our application is because we have local data storage on the device, and some of the data could be left in an unusable state if neither of the completion handler/failure handler got executed.

Having realized that inactivity timeouts were not going to be a concern, we stumbled across a different problem. We still needed to come up with a solution to execute the failure handlers of any asynchronous operations in case the user/iOS decided to kill the app.

This post on the apple developer forums seems like a promising approach to resolve this concern, but we are yet to investigate it further. May be a future post.

--

--

Avanish Rayankula

Software developer, been working on iOS Apps for the last couple of years