允许用户选择要在Swift中拨打的应用

时间:2017-04-23 11:30:30

标签: ios swift skype phone-call viber

我找到了让用户通过我的应用拨打电话的方法。但是,我希望用户能够从(电话,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);
                    }
                }
            }
        }
    }

有没有办法让它像swift中的社交分享一样工作。谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

有一种称为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
Viber:https://developers.viber.com/tools/deep-links/index.html