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

Calling a Phone Number

The SDLDialNumber RPC allows you make a phone call via the user's phone. Regardless of platform (Android or iOS), you must be sure that a device is connected via Bluetooth (even if using USB) for this RPC to work. If the phone is not connected via Bluetooth, you will receive a result of REJECTED from Core.

Note

SDLDialNumber is an RPC that is usually restricted by OEMs. As a result, the OEM you are connecting to may limit app functionality if not approved for usage.

Checking if Dial Number is Available

SDLDialNumber is a newer RPC, so there is a possibility that not all head units will support it. To find out if the RPC is supported by the head unit, check the system capability manager's hmiCapabilities.phoneCall property after the manager has been started successfully.

Objective-C
[self.sdlManager.systemCapabilityManager updateCapabilityType:SDLSystemCapabilityTypePhoneCall completionHandler:^(NSError * _Nullable error, SDLSystemCapabilityManager * _Nonnull systemCapabilityManager) {
    BOOL isDialNumberSupported = NO;
    if (error == nil) {
        isDialNumberSupported = systemCapabilityManager.phoneCapability.dialNumberEnabled.boolValue;
    }
    else {
        isDialNumberSupported = systemCapabilityManager.hmiCapabilities.phoneCall.boolValue;
    }

    <#If making phone calls is supported, send the `DialNumber` RPC#>
}];
Swift
sdlManager.systemCapabilityManager.updateCapabilityType(.phoneCall) { (error, systemCapabilityManager) in
    var isDialNumberSupported = false
    if error == nil {
        isDialNumberSupported = systemCapabilityManager.phoneCapability?.dialNumberEnabled?.boolValue ?? false;
    } else {
        isDialNumberSupported = systemCapabilityManager.hmiCapabilities?.phoneCall?.boolValue ?? false
    }

    <#If making phone calls is supported, send the `DialNumber` RPC#>
}

Sending a DialNumber Request

Note

DialNumber strips all characters except for 0-9, *, #, ,, ;, and +.

Objective-C
SDLDialNumber *dialNumber = [[SDLDialNumber alloc] initWithNumber: @"1238675309"];

[self.sdlManager sendRequest:dialNumber withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
    if (error != nil || ![response isKindOfClass:SDLDialNumberResponse.class]) {
        <#Encountered error sending DialNumber#>
        return;
    }

    SDLDialNumberResponse* dialNumber = (SDLDialNumberResponse *)response;
    SDLResult *resultCode = dialNumber.resultCode;
    if (![resultCode isEqualToEnum:SDLResultSuccess]) {
        if ([resultCode isEqualToEnum:SDLResultRejected]) {
            <#DialNumber was rejected. Either the call was sent and cancelled or there is no device connected#>
        } else if ([resultCode isEqualToEnum:SDLResultDisallowed]) {
            <#Your app is not allowed to use DialNumber#>
        } else {    
            <#Some unknown error has occurred#>
        }
        return;
    }

    <#DialNumber successfully sent#>
}];
Swift
let dialNumber = SDLDialNumber(number: "1238675309")

sdlManager.send(request: dialNumber) { (request, response, error) in
    guard let response = response as? SDLDialNumberResponse, error == nil else {
        <#Encountered error sending DialNumber#>
        return
    }

    guard response.resultCode == .success else {
        switch response.resultCode {
        case .rejected:
            <#DialNumber was rejected. Either the call was sent and cancelled or there is no device connected#>
        case .disallowed:
            <#Your app is not allowed to use DialNumber#>
        default:
            <#Some unknown error has occurred#>
        }
        return
    }

    <#DialNumber successfully sent#>
}

DialNumber Result

DialNumber has 3 possible results that you should expect:

  1. SUCCESS - DialNumber was successfully sent, and a phone call was initiated by the user.
  2. REJECTED - DialNumber was sent, and a phone call was cancelled by the user. Also, this could mean that there is no phone connected via Bluetooth.
  3. DISALLOWED - Your app does not have permission to use DialNumber.
View on GitHub.com
Previous Section Next Section