我正在尝试制作一个联系人电话簿应用程序,通过点击电话号码,如果将启动以打开通话应用程序或短信应用程序。
到目前为止,我已经找到了这些选项:
UIApplication.shared.open(tlfURL, options: [:], completionHandler: nil)
UIApplication.shared.open(smsURL, options: [:], completionHandler: nil)
那些必须单独调用。 有没有办法通过点击标签一次来触发它们,调用和短信启动选项?
如果没有任何建议如何实现? UIActivityViewController ?
谢谢
最佳答案
我会用一个
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)
关于ios - 点击标签时同时调用和短信选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52540004/