[英]How to run code after phone calling in Swift
我点击按钮进行通话。 我的代码:
if let phoneCallURL:NSURL = NSURL(string: "tel://\(phoneNumber)") {
let application:UIApplication = UIApplication.shared
if (application.canOpenURL(phoneCallURL as URL)) {
application.openURL(phoneCallURL as URL);
}
else {
let alertController = UIAlertController(title: NSLocalizedString("CALL_C_TITLE", comment: "Call disallowed"), message: NSLocalizedString("CALL_C_DESC", comment: "This device cannot call"), preferredStyle: UIAlertControllerStyle.actionSheet)
alertController.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "OK"), style: UIAlertActionStyle.default, handler: nil))
self.present(alertController, animated: true, completion: nil)
}
}
此代码工作正常,但我想在用户端调用后运行一些代码。 我该怎么做?
当呼叫结束并且您的应用程序重新获得焦点时,它将收到UIApplicationDidBecomeActive
( docs )通知。 您可以将ViewController注册为观察者,然后做出相应的响应。
请记住,您也会收到其他事件序列的此通知(从后台返回,取消通知等),因此您可能希望在启动呼叫时设置一个标志,并仅在通知处理程序中检查该标志想要在调用后运行代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.