【问题标题】:Allow user to choose an app to dial with in Swift允许用户在 Swift 中选择要拨号的应用
【发布时间】:2023-04-07 08:00:01
【问题描述】:

我找到了一种让用户通过我的应用拨打电话的方法。但是,我希望用户能够选择从哪个应用程序(电话、Viber、Skype)拨打电话,类似于社交分享功能,但用于电话。

我现在用这个直接拨号:

public static func callNumber(phoneNumber: String) {  
let cleanPhoneNumber = phoneNumber.trimmingCharacters(in: CharacterSet(charactersIn: "01234567890").inverted)
        if let phoneCallURL = URL(string: "tel://\(cleanPhoneNumber)")  {
            if UIDevice.current.model.range(of: "iPad") != nil {
                print("Your device doesn't support this feature.")
            } else {
                let application: UIApplication = UIApplication.shared
                if (application.canOpenURL(phoneCallURL)) {
                    let mobileNetworkCode = CTTelephonyNetworkInfo().subscriberCellularProvider?.mobileNetworkCode
                    if( mobileNetworkCode == nil) {
                        print(" No sim present Or No cellular coverage or phone is on airplane mode.")
                    }
                    else {
                        application.openURL(phoneCallURL);
                    }
                }
            }
        }
    }

有没有办法让它像社交分享一样快速运行。感谢您的帮助。

【问题讨论】:

  • 欢迎来到 SO!请阅读此how-to-ask 并显示您尝试解决问题的代码。

标签: ios swift skype phone-call viber


【解决方案1】:

有一种叫做 URL shemes (URI) 的东西。 https://useyourloaf.com/blog/querying-url-schemes-with-canopenurl/

func open(scheme: String) {
  if let url = URL(string: scheme) {
    UIApplication.shared.open(url, options: [:], completionHandler: {
      (success) in
      print("Open \(scheme): \(success)")
    })
  }
}

open(scheme: "skype:<params>")
open(scheme: "viber:<params>")

Skype:https://msdn.microsoft.com/en-us/library/office/dn745885.aspx
维伯:https://developers.viber.com/tools/deep-links/index.html

【讨论】:

    猜你喜欢
    • 2014-10-20
    • 2012-11-13
    • 2019-07-07
    • 2016-08-15
    • 2019-05-14
    • 1970-01-01
    • 1970-01-01
    • 2017-02-25
    • 2022-01-03
    相关资源
    最近更新 更多