ios - 点击标签时同时调用和短信选项

标签 ios swift sms call

我正在尝试制作一个联系人电话簿应用程序,通过点击电话号码,如果将启动以打开通话应用程序或短信应用程序。

到目前为止,我已经找到了这些选项:

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/

相关文章:

ios - NSKeyedUnarchiver.unarchiveTopLevelObjectWithData 在 Swift 4 中被废弃

ios - 哪个是 objective-c 中更快的运算符

twilio - 为什么我不能向墨西哥的来电者发送 Twilio 验证短信?

ios - Swift - iOS - 不同格式的日期和时间

ios - swift uitableview 重新排序除最后一个单元格之外的单元格

ios - 如何将 CXCallController 置于最前面

swift - 为什么我可以在没有框架引用的情况下使用 MessageUI?

ios - 我们可以将 NSPointerArray 转换为 Array 吗?

android - 如何在没有互联网连接的情况下与服务器通信?

php - 通过 PHP mail() 函数发送短信时出现 'From' header 问题