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()
}
}