Dial USSD code in iOS?

How to Dial USSD code in iOS?

What is USSD?
USSD (Unstructured Supplementary Service Data) is a communications protocol used by GSM cellular telephones to communicate with the mobile network operator’s computers.

Generally, the USSD code is used by apps for start Call Forwarding, To get some system info, USSD based banking services, etc.

Previously, iOS didn’t allow to dial special chars like “*” and “#” programmatically from the iOS app, to prevent users from malicious redirecting phone calls or changing the behavior of a phone or account. So dialing codes programmatically was not possible till iOS 10.

With the launch of iOS 11 Apple enabled developers to programmatically dial USSD code from iOS app with some limitations.


How to dial USSD code:                                                       

Use below piece of Swift code to invoke dialing of USSD codes

let ussdCode = "tel://{your_USSD_number}"

        let app = UIApplication.shared

        if let encoded = ussdCode.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {

            let u = encoded//"tel://\(encoded)"

            if let url = URL(string:u) {

                if app.canOpenURL(url) {

                    app.open(url, options: [:], completionHandler: { (finished) in

                        if finished{

                            //Do your stuff



When the above code gets executed, the app user will be shown a Dial prompt like below and will have to choose an action.

Note:  To dial USSD code with “#” you have to encode it like shown below else you will not get prompt for a number which contains “#”.

addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)


If you are interested to know about the status of this call you have made to dial USSD, check below

How to Track Ongoing Call Status:

We can track Dialled call status like call dialling, running, completed using callKit framework. CallKit is a new framework that aims to improve the VoIP experience by allowing apps to integrate tightly with the native Phone UI. CallKit has many functionalities that work with VoIP calling but here we are using it only to track dialed call status.

Implement Callkit in swift to check call status as follows:

Import required Library

import CallKit

Use Protocol and Delegate method :-

class viewController: UIViewController, CXCallObserverDelegate{

func callObserver(_ callObserver: CXCallObserver, callChanged call: CXCall) {

        if call.hasEnded == true {

            print("CXCallState :Ended")


        if call.isOutgoing == true && call.hasConnected == false {

            print("CXCallState :Dialing")


        if call.isOutgoing == false && call.hasConnected == false && call.hasEnded == false {

            print("CXCallState :Incoming")



        if call.hasConnected == true && call.hasEnded == false {

            print("CXCallState : Connected")




Thats it for now folks. Happy Coding!

Leave a Reply

Your email address will not be published. Required fields are marked *