ios - 允许用户选择要在 Swift 中拨号的应用程序

标签 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);
                    }
                }
            }
        }
    }

有没有办法让它像社交共享一样快速工作。感谢您的帮助。

最佳答案

有一种叫做 URL 方案 (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

关于ios - 允许用户选择要在 Swift 中拨号的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43570588/

相关文章:

ios - Cell 中只有第一个 UILabel,更新了 UICollectionView - Swift

ios - 如何将标题 View 添加到 UICollectionView

iphone - Skype 整合问题

ios - Sprite Kit - 更改 SKShapeNode 的 anchor 不会更改 SKPhysicalBody 位置

Swift:为变量生成标识符

status - 如何以数字或文本形式获取Skype状态? mystatus.skype.com 不起作用

ios - MFMailComposeViewController, Swift 4, Xcode 9

ios - 从 Xamarin.iOS 绑定(bind)库引用 Storyboard

ios - swift 自动布局 : constraints in sub-view not working