“tel://”链接在 iPhone 模拟器上不起作用

Sha*_*jon 1 url tel ios swiftui

我有一个手机号码(孟加拉国号码)。我希望当我单击“紧急呼叫”按钮时,我的应用程序将带我到 iPhone 的默认电话应用程序进行呼叫。但是,我有两个按钮,分别称为“Call For Query”和“Emergency Call”。在第一个按钮中,我使用链接“https://google.com”,它非常好用。但不是带有手机号码的第二个按钮。当我按下第二个按钮时,它会出现以下错误:

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

是不是因为 iPhone 模拟器中没有电话应用程序?

这是我的代码:

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()
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 5

没有用于 iphone 模拟器的电话应用程序,因此 tel:// 无法在模拟器中打开该应用程序。请在真正的 iphone 上检查一下,它会完美运行。