# Transitions

Handling transitions correctly with your app during a live video and/or audio call is critical for a pleasant user experience. This section details how to handle these transitions.

## Audio Background Mode

The UIBackgroundModes key needs to be configured to provide audio in your app's plist file. These details are covered in Updating your Application's plist File.

## Handling Transitions

In your app's delegate, implement the following code. This will allow audio to continue to transmit and receive while your app is in the background. It will also mute the video transmitting while your app is in the background and unmute the video when your app goes back to the foreground.

    @implementation YourAppDelegate {
        BOOL wasVideoOutUnmutedOnEnterBackground;
    }

    - (void)applicationDidEnterBackground:(UIApplication *)application
    {
        // When the app goes into background, the video stops.  If the video was muted before entering
        // the background, it will remain muted when returning to the foreground.

        CJGuestCall * activeCall = [CJGuestCall sharedInstance];

        if ([activeCall getCallState] == GuestCallStateConnected) {
            [activeCall audioSetActive:NO];

            wasVideoOutUnmutedOnEnterBackground = !activeCall.isVideoOutMuted;

            // We will notify the server that we are muting the video if need be.
            if (wasVideoOutUnmutedOnEnterBackground)
                [activeCall muteVideoOut];
        }
    }

    - (void)applicationWillEnterForeground:(UIApplication *)application
    {
        CJGuestCall * activeCall = [CJGuestCall sharedInstance];

        if ([activeCall getCallState] == GuestCallStateConnected) {
            [activeCall audioSetActive:YES];

            if (wasVideoOutUnmutedOnEnterBackground)
                [activeCall unmuteVideoOut];
        }
    }

Also add the following code to your app's delegate to handle your app terminating.

    - (void)applicationWillTerminate:(UIApplication *)application
    {
        [[CJGuestCall sharedInstance] endCall];
    }

### CJGuestCallViewController

If you are using the high-level CJGuestCallViewController piece of the SDK, these transition details are wrapped up into helper methods that you can call directly on the CJGuestCallViewController object. These are here for your convenience, using them allows you to have a working demo in a matter of minutes.

If you want to use these helper methods, implement the following code in your app's delegate. This code assumes you have an instance of the CJGuestCallViewController object named jabberGuest available.

    - (void)applicationDidEnterBackground:(UIApplication *)application
    {
        [jabberGuest enterBackground];
    }

    - (void)applicationWillEnterForeground:(UIApplication *)application
    {
        [jabberGuest enterForeground];
    }

    - (void)applicationWillTerminate:(UIApplication *)application
    {
        [jabberGuest terminate];
    }