Hello everyone,
We are using a stream layer in our iOS app (e.g., the SandyVehicles Layer from ESRI), and it works well overall. However, we’ve noticed that when the device screen is locked, the stream layer stops functioning, and the layer features stop updating or moving.
Is this a known issue? If so, are there any workarounds or solutions available?
Thanks in advance for your help.
Marvin
Hi Marvin, thanks for the question. First, I'll explain the expected behaviors; then, I'll propose a workaround.
Behaviors
- On a Simulator, if you try to lock then unlock, the streaming service will remain active.
- On a real device, the streaming service will show a "failed" status when the device is unlocked and the app is reopened.
Why?
Think ArcGIS Stream Service as an underlying WebSocket implementation.
iOS has a notoriously rigid background timeframe for an app. When the lock button is tapped, if I'm not mistaken, the app is immediately suspended without OS giving the app any time to finish remaining tasks.
That means, any ongoing network request is terminated. If you catch the model.streamService.connectionError as NSError, you'll see that the OS aborted the connection.
How to mitigate?
AFAIK, iOS doesn't have a legitimate way to keep a background connection alive. True that there are background tasks that allow the app to periodically check-in with the server, but that doesn't guarantee a keepalive styled connection like the stream service.
Instead, I would recommend monitoring the streamService.$connectionStatus property. When it reaches a failed state, reconnect to the stream service.
Hi @Ting,
thank you for the clarification. Your explanation makes sense. But to clarify, the iOS app is not directly creating or managing the stream layer. Instead, the layer is configured and added to a map within the ArcGIS Enterprise portal (e.g., the SandyVehicles layer), similar to how standard feature layers are managed. The app simply uses this map, fetching the stream layer as part of the map's content.
While the layer generally functions well (updating features correctly in the app) it encounters an issue when the device's screen is locked. Upon unlocking, the map needs to be reloaded to restore proper functionality.
Given this context, is there a workaround to address the issue without relying on a Stream Service instance?
Thanks for the additional information. I can understand that the portal item should handle the lost-connection restoration. We'll need to discuss ways to improve it. Will keep you updated.
Meanwhile, DynamicEntityLayer.dataSource contains the methods to connect/disconnect from a stream service. Until we have better auto-connection handling, some manually work might have to be in place.