The "tel://" link doesn't work on iPhone Simulator
Asked Answered
M

1

7

I have one mobile number (Bangladeshi Number). I want my app will take me to the iPhone's default Phone app to make a call when I will click on the "Emergency Call" Button. However, I have two button called "Call For Query" and "Emergency Call". In first button I use the link "https://google.com", which works absolutely fine. But not the second button with the mobile number. When I press the second button it gives the following error:

Failed to open URL tel://+8801700000001: Error Domain=NSOSStatusErrorDomain Code=-10814 "(null)" UserInfo={_LSLine=247, _LSFunction=-[_LSDOpenClient openURL:options:completionHandler:]}

Is it because the Phone app is not available in the iPhone Simulators?

Here is my code:

import SwiftUI

struct CallUsView: View {
    @State var callForEmergency: String = "+8801700000001"
    
    var body: some View {
        GeometryReader { geometry in
            ZStack {
                Image("App Background")
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .offset(y: -geometry.size.height/3)
                VStack {
                    Button(action: {
                        if self.callForQuery != "" {
                            let mobileURL = "https://google.com"
                            guard let url = URL(string: mobileURL) else { return }
                            UIApplication.shared.open(url)
                        }
                    }) {
                        Image("Call For Query")
                    }
                    .buttonStyle(PlainButtonStyle())
                    Button(action: {
                        if self.callForEmergency != "" {
                            let mobileURL = "tel://\(self.callForEmergency)"
                            guard let url = URL(string: mobileURL) else { return }
                            UIApplication.shared.open(url)
                        }
                    }) {
                        Image("Emergency Call")
                    }
                    .buttonStyle(PlainButtonStyle())
                }
            }
        }
    }
}

struct CallUsView_Previews: PreviewProvider {
    static var previews: some View {
        CallUsView()
    }
}
Milwaukee answered 4/7, 2020 at 9:20 Comment(0)
K
16

There is no phone app for an iphone simulator and so tel:// is unable to open the app in a simulator. Please check this in a real iphone, it will work perfectly.

Kore answered 4/7, 2020 at 10:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.