Expand Minimize Picture-in-picture Power Device Status Voice Recognition Skip Back Skip Forward Minus Plus Play Search
Documentation
Sidebar

Slider

A SDLSlider creates a full screen or pop-up overlay (depending on platform) that a user can control. There are two main SDLSlider layouts, one with a static footer and one with a dynamic footer.

Note

The slider will persist on the screen until the timeout has elapsed or the user dismisses the slider by selecting a position or canceling.

Slider

A slider popup with a static footer displays a single, optional, footer message below the slider UI. A dynamic footer can show a different message for each slider position.

Slider UI

Slider with Static Footer 1

Dynamic Slider in Position 1

Slider with Dynamic Footer 1

Dynamic Slider in Position 2

Slider with Dynamic Footer 2

Creating the Slider

Objective-C
// Create the slider
SDLSlider *sdlSlider = [[SDLSlider alloc] init];
Swift
// Create the slider
let sdlSlider = SDLSlider()

Ticks

The number of selectable items on a horizontal axis.

Objective-C
// Must be a number between 2 and 26
sdlSlider.numTicks = @(5);
Swift
// Must be a number between 2 and 26
sdlSlider.numTicks = 5

Position

The initial position of slider control (cannot exceed numTicks).

Objective-C
// Must be a number between 1 and 26
sdlSlider.position = @(1);
Swift
// Must be a number between 1 and 26
sdlSlider.position = 1

The header to display.

Objective-C
// Max length 500 chars
sdlSlider.sliderHeader = @"This is a Header";
Swift
// Max length 500 chars
sdlSlider.sliderHeader = "This is a Header"

The footer will have the same message across all positions of the slider.

Objective-C
// Max length 500 chars
sdlSlider.sliderFooter = @[@"Static Footer"];
Swift
// Max length 500 chars
sdlSlider.sliderFooter = ["Static Footer"]

This type of footer will have a different message displayed for each position of the slider. The footer is an optional paramater. The footer message displayed will be based off of the slider's current position. The footer array should be the same length as numTicks because each footer must correspond to a tick value. Or, you can pass nil to have no footer at all.

Objective-C
// Array length 1 - 26, Max length 500 chars
NSArray<NSString *> *footers = @[@"Footer 1", @"Footer 2", @"Footer 3"];
sdlSlider.sliderFooter = footers;
Swift
// Array length 1 - 26, Max length 500 chars
let footers = ["Footer 1", "Footer 2", "Footer 3"]
sdlSlider.sliderFooter = footers

Cancel ID

An ID for this specific slider to allow cancellation through the CancelInteraction RPC.

Objective-C
sdlSlider.cancelID = @(45);
Swift
sdlSlider.cancelID = 45

Show the Slider

Objective-C
[manager sendRequest:sdlSlider withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
    if (!response || !response.success.boolValue) {
        SDLLogE(@"Error getting the SDLSlider response");
        return;
    }

    // Create a SDLSlider response object from the handler response
    SDLSliderResponse *sdlSliderResponse = (SDLSliderResponse *)response;
    NSUInteger position = sdlSliderResponse.sliderPosition.unsignedIntegerValue;

    <#Use the slider position#>
}];
Swift
manager.send(request: sdlSlider, responseHandler: { (req, res, err) in
    // Create a SDLSlider response object from the handler response
    guard let response = res as? SDLSliderResponse, response.resultCode == .success, let position = response.sliderPosition.intValue else { return }

    <#Use the slider position#>
})

Dismissing a Slider (RPC v6.0+)

You can dismiss a displayed slider before the timeout has elapsed by dismissing either a specific slider or the current slider.

Note

If connected to older head units that do not support this feature, the cancel request will be ignored, and the slider will persist on the screen until the timeout has elapsed or the user dismisses by selecting a position or canceling.

Dismissing a Specific Slider

Objective-C
// `cancelID` is the ID that you assigned when creating the slider
SDLCancelInteraction *cancelInteraction = [[SDLCancelInteraction alloc] initWithSliderCancelID:cancelID];
[self.sdlManager sendRequest:cancelInteraction withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
    if (![response.resultCode isEqualToEnum:SDLResultSuccess]) { return; }
    <#The slider was canceled successfully#>
}];
Swift
// `cancelID` is the ID that you assigned when creating the slider
let cancelInteraction = SDLCancelInteraction(sliderCancelID: cancelID)
sdlManager.send(request: cancelInteraction) { (request, response, error) in
    guard response?.resultCode == .success else { return }
    <#The slider was canceled successfully#>
}

Dismissing the Current Slider

Objective-C
SDLCancelInteraction *cancelInteraction = [SDLCancelInteraction slider];
[self.sdlManager sendRequest:cancelInteraction withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
    if (![response.resultCode isEqualToEnum:SDLResultSuccess]) { return; }
    <#The slider was canceled successfully#>
}];
Swift
let cancelInteraction = SDLCancelInteraction.slider()
sdlManager.send(request: cancelInteraction) { (request, response, error) in
    guard response?.resultCode == .success else { return }
    <#The slider was canceled successfully#>
}
View on GitHub.com
Previous Section Next Section