Expand Minimize Picture-in-picture Power Device Status Voice Recognition Skip Back Skip Forward Minus Plus Play Search
Internet Explorer alert
This browser is not recommended for use with smartdevicelink.com, and may not function properly. Upgrade to a different browser to guarantee support of all features.
close alert
To Top Created with Sketch. To Top
To Bottom Created with Sketch. To Bottom
iOS Guides
Batch Sending RPCs

Batch Sending RPCs

There are two ways to send multiple requests to the head unit: concurrently and sequentially. Which method you should use depends on the type of RPCs being sent. Concurrently sent requests might finish in a random order and should only be used when none of the requests in the group depend on the response of another, such as when subscribing to several hard buttons. Sequentially sent requests only send the next request in the group when a response has been received for the previously sent RPC. Requests should be sent sequentially when you need to know the result of a previous request before sending the next, like when sending the several different requests needed to create a menu.

Both methods have optional progress and completion handlers. Use the progressHandler to check the status of each sent RPC; it will tell you if there was an error sending the request and what percentage of the group has completed sending. The optional completionHandler is called when all RPCs in the group have been sent. Use it to check if all of the requests have been sent successfully or not.

Sending Concurrent Requests

When you send multiple RPCs concurrently, it will not wait for the response of the previous RPC before sending the next one. Therefore, there is no guarantee that responses will be returned in order, and you will not be able to use information sent in a previous RPC for a later RPC.

SDLSubscribeButton *subscribeButtonLeft = [[SDLSubscribeButton alloc] initWithButtonName:SDLButtonNameSeekLeft handler:^(SDLOnButtonPress * _Nullable buttonPress, SDLOnButtonEvent * _Nullable buttonEvent) {
    <#code#>
}];
SDLSubscribeButton *subscribeButtonRight = [[SDLSubscribeButton alloc] initWithButtonName:SDLButtonNameSeekRight handler:^(SDLOnButtonPress * _Nullable buttonPress, SDLOnButtonEvent * _Nullable buttonEvent) {
    <#code#>
}];
[self.sdlManager sendRequests:@[subscribeButtonLeft, subscribeButtonRight] progressHandler:^(__kindof SDLRPCRequest * _Nonnull request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error, float percentComplete) {
    <#Called as each request completes#>
} completionHandler:^(BOOL success) {
    <#Called when all requests complete#>
}];
let subscribeButtonLeft = SDLSubscribeButton(buttonName: SDLButtonName.seekLeft) { (onButtonPress, onButtonEvent) in
    <#code#>
}
let subscribeButtonRight = SDLSubscribeButton(buttonName: SDLButtonName.seekRight) { (onButtonPress, onButtonEvent) in
    <#code#>
}
sdlManager.send([subscribeButtonLeft, subscribeButtonRight], progressHandler: { (request, response, error, percentComplete) in
    <#Called as each request completes#>
}) { success in
    <#Called when all requests complete#>
}

Sending Sequential Requests

Requests sent sequentially are sent in a set order. The next request is only sent when a response has been received for the previously sent request.

The code example below shows how to create a perform interaction choice set. When creating a perform interaction choice set, the SDLPerformInteraction RPC can only be sent after the SDLCreateInteractionChoiceSet RPC has been registered by Core, which is why the requests must be sent sequentially.

SDLChoice *choice = [[SDLChoice alloc] initWithId:<#Choice Id#> menuName:@"<#Menu Name#>" vrCommands:@[@"<#VR Command#>"]];
SDLCreateInteractionChoiceSet *createInteractionChoiceSet = [[SDLCreateInteractionChoiceSet alloc] initWithId:<#Choice Set Id#> choiceSet:@[choice]];
SDLPerformInteraction *performInteraction = [[SDLPerformInteraction alloc] initWithInitialText:<#(nonnull NSString *)#> interactionMode:<#(nonnull SDLInteractionMode)#> interactionChoiceSetIDList:<#(nonnull NSArray<NSNumber<SDLUInt> *> *)#> cancelID:<#(UInt32)#>];

[self.sdlManager sendSequentialRequests:@[createInteractionChoiceSet, performInteraction] progressHandler:^BOOL(__kindof SDLRPCRequest * _Nonnull request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error, float percentComplete) {
    <#Called as each request completes#>
    return YES;
} completionHandler:^(BOOL success) {
    <#Called when all requests complete#>
}];
let choice = SDLChoice(id: <#Choice Id#>, menuName: "<#Menu Name#>", vrCommands: ["<#VR Command#>"])
let createInteractionChoiceSet = SDLCreateInteractionChoiceSet(id: <#Choice Set Id#>, choiceSet: [choice])
let performInteraction = SDLPerformInteraction(interactionChoiceSetId: <#Choice Set Id#>)
let performInteraction = SDLPerformInteraction(initialText: <#String#>, interactionMode: <#SDLInteractionMode#>, interactionChoiceSetIDList: <#[NSNumber & SDLUInt]#>, cancelID: <#UInt32#>)

sdlManager.sendSequential(requests: [createInteractionChoiceSet, performInteraction], progressHandler: { (request, response, error, percentageCompleted) -> Bool in
    <#Called as each request completes#>
    return true
}) { success in
    <#Called when all requests complete#>
}
View on GitHub.com
Previous Section Next Section