【问题标题】:How to make phone call with SwiftUI [duplicate]如何使用 SwiftUI 拨打电话 [重复]
【发布时间】:2020-02-25 15:31:07
【问题描述】:

如何在 SwiftUI 中拨打电话。以下是 Swift 和 UIKit 的示例代码:

guard let number = URL(string: "tel://" + "+1(222)333-44-55") else { return }
UIApplication.shared.open(number)

这里是 Swift 和 UIKit 版本的主题:

How to make phone call in iOS 10 using Swift?

【问题讨论】:

标签: ios swift uikit swiftui


【解决方案1】:
let numberString = "111-222-3334"

Button(action: {
    let telephone = "tel://"
    let formattedString = telephone + numberString
    guard let url = URL(string: formattedString) else { return }
    UIApplication.shared.open(url)
   }) {
   Text(numberString)
}

【讨论】:

  • 我想知道这与使用URLComponents 并将方案设置为"tel" 相比如何。它抽象了://,所以感觉更“合适”,但我不确定它是否更可取
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-26
  • 2012-06-17
  • 1970-01-01
  • 2023-03-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多