How to keep an App connected to RC server in the iOS background?

This article explains how to force an App to maintain a long connection with RC server in the iOS background.

Prerequisites

Your App must have permission to stay active in the iOS background for extended periods. If not, skip this guide and use the SDK’s default settings.

In iOS, most Apps are suspended after running in the background for a while. The SDK handles this by default.

After two minutes in the background, the long connection with RC is disconnected, and messages are pushed via APNS for a better user experience.

Some Apps, like those for audio and video playback, peripheral devices, IoT, or jailbreak, can stay active in the background. These Apps can configure the SDK to maintain a permanent long connection.

Implementation steps

Here’s how to force a permanent long connection in the iOS background for RC IM SDK versions before and after 5.16.1.

After version 5.16.1

Set the ForceKeepAlive property in RCLocalConfiguration to manage the keepalive status.

For example, set it to YES during audio and video playback, and NO when playback ends.


[RCLocalConfiguration sharedInstance].forceKeepAlive = YES;

Before version 5.16.1

Import the following category and use its methods to enable or disable IM keepalive. Set to YES for keepalive:

longlive.zip (1.7 KB)

Note: After enabling a permanent long connection, manually disconnect based on your App’s needs. Align the keepalive settings with your project’s lifecycle.

If your App doesn’t have background activity permissions, use the SDK’s default settings. This ensures RC can detect when the client goes offline and push remote notifications.