我正在尝试通过点击电话号码来制作联系人电话簿应用程序,如果该应用程序可以启动以打开呼叫应用程序或短信应用程序。
到目前为止,我已经找到了以下选项:
UIApplication.shared.open(tlfURL, options: [:], completionHandler: nil)
UIApplication.shared.open(smsURL, options: [:], completionHandler: nil)
必须分别调用它们。 有没有一种方法可以通过一次点击标签来触发二者(呼叫和短信启动选项)?
如果没有任何建议如何实施呢? UIActivityViewController吗?
谢谢
答案 0 :(得分:2)
我会使用
UIAlertController
使用
preferredStyle: .actionSheet
它将帮助您向用户显示多个选项,让他们选择他们想做的事情。看起来像这样:
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) // makes a new UIAlertController with no title or message
// makes a new UIAlertAction to call on tap
let callAction = UIAlertAction(title: "Call", style: .default) { _ in
UIApplication.shared.open(tlfURL, options: [:], completionHandler: nil)
}
// makes a new UIAlertAction to sms on tap
let smsAction = UIAlertAction(title: "SMS", style: .default) { _ in
UIApplication.shared.open(smsURL, options: [:], completionHandler: nil)
}
// makes a new cancel action so the user can decide not to take any actions
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
// add the actions to the UIAlertController
alertController.addAction(callAction)
alertController.addAction(smsAction)
alertController.addAction(cancelAction)
// present the UIAlertController to the user so they can interact with it
present(alertController, animated: true, completion: nil)