我刚接触Swift语言和编码。我创建了一个可以调用手机号码的功能,并创建了一个可以发送文本短信的功能。调用函数完成后,sendJSON将执行。 有人能帮我吗。感谢
通话功能
func call() {
if let telephoneURL = URL(string: "tel://\(dispatchNumber.replacingOccurrences(of: " ", with: ""))") { //Calling on the phone
if #available(iOS 10.0, *) {
UIApplication.shared.open(telephoneURL, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(telephoneURL)
}
}
}
SendSMS功能
func sendJSON() {
let messageVC = MFMessageComposeViewController()
if(MFMessageComposeViewController.canSendText())
{
messageVC.messageComposeDelegate = self
messageVC.body = "test"
messageVC.recipients = "123456789"
UIApplication.shared.keyWindow?.rootViewController?.present(messageVC, animated: true, completion: nil)
}
}
答案 0 :(得分:0)
您需要为此
使用completionHandlerfunc call() {
if let telephoneURL = URL(string: "tel://\(dispatchNumber.replacingOccurrences(of: " ", with: ""))") { //Calling on the phone
if #available(iOS 10.0, *) {
UIApplication.shared.open(telephoneURL, options: [:], completionHandler: {[weak seld] in
self?.sendJSON()
})
} else {
UIApplication.shared.openURL(telephoneURL)
}
}
}