Ios 为什么当我的警报试图弹出时会出现线程1:EXC_断点?
我不太擅长调试和找出错误。因此,我的应用程序基本上有一个通知,当按下通知上显示“Call”的操作时,会弹出一个警报,它会调用您在安排通知时最初在UITextField中输入的号码。当该操作出于某种原因将我带入应用程序时,我甚至没有收到警报,并弹出一个Ios 为什么当我的警报试图弹出时会出现线程1:EXC_断点?,ios,swift,swift3,Ios,Swift,Swift3,我不太擅长调试和找出错误。因此,我的应用程序基本上有一个通知,当按下通知上显示“Call”的操作时,会弹出一个警报,它会调用您在安排通知时最初在UITextField中输入的号码。当该操作出于某种原因将我带入应用程序时,我甚至没有收到警报,并弹出一个线程1:EXC_断点错误。任何帮助都会很棒:)谢谢。以下是我的代码,问题可能来自: 在my ViewController子类中: func showAlert(title: String, message : String, buttonTitle1
线程1:EXC_断点
错误。任何帮助都会很棒:)谢谢。以下是我的代码,问题可能来自:
在my ViewController子类中:
func showAlert(title: String, message : String, buttonTitle1: String, buttonTitle2: String,window: UIWindow){
// create the alert
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
// add the actions (buttons)
alert.addAction(UIAlertAction(title: buttonTitle1, style: UIAlertActionStyle.default, handler: { action in
if let url = URL(string: "tel://\(self.phoneNumber.text)") {
UIApplication.shared.open(url, options: [:])
}
}))
alert.addAction(UIAlertAction(title: buttonTitle2, style: UIAlertActionStyle.cancel, handler: nil))
// show the alert
self.present(alert, animated: true, completion: nil)
}
//Main Stuff
var window: UIWindow?
和ViewController扩展:
extension ViewController: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
if response.actionIdentifier == "call" {
self.showAlert(title: "Enter Call", message: "Are you sure?", buttonTitle1: "Go", buttonTitle2: "Cancel", window: self.window!)
}
}
}
要关闭意外断点,可以转到“断点导航器” 沿着Xcode窗口的左侧,您将看到一个看起来像梯形的图标(这是屏幕截图左上角的红色圆圈): 虽然我只是在屏幕截图中设置了一个断点,但您的项目中可能设置了更多断点(这是偶然的)。如果切换蓝色标志,断点将被禁用。您可以将该标志拖离该列,断点将被删除 您也可以按住control键,同时单击该标志,您将看到一个弹出菜单,允许您执行相同的操作
最后,在Xcode的“调试”菜单中有一个“停用断点”菜单选项,您可以在“停用”和“激活”之间切换菜单。要关闭意外断点,您可以转到“断点导航器” 沿着Xcode窗口的左侧,您将看到一个看起来像梯形的图标(这是屏幕截图左上角的红色圆圈): 虽然我只是在屏幕截图中设置了一个断点,但您的项目中可能设置了更多断点(这是偶然的)。如果切换蓝色标志,断点将被禁用。您可以将该标志拖离该列,断点将被删除 您也可以按住control键,同时单击该标志,您将看到一个弹出菜单,允许您执行相同的操作
最后,在Xcode的“Debug”菜单中有一个“Deactivate Breakpoints”菜单选项,您可以在“Deactivate”和“Activate”之间切换菜单。您可能会遇到崩溃,因为您在主线程之外启动UI活动。尝试将UIAlert调用包装到DispatchQueue中,如下所示:
func showAlert(title: String, message : String, buttonTitle1: String, buttonTitle2: String,window: UIWindow){
DispatchQueue.main.async {
// create the alert
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
// add the actions (buttons)
alert.addAction(UIAlertAction(title: buttonTitle1, style: UIAlertActionStyle.default, handler: { action in
if let url = URL(string: "tel://\(self.phoneNumber.text)") {
UIApplication.shared.open(url, options: [:])
}
}))
alert.addAction(UIAlertAction(title: buttonTitle2, style: UIAlertActionStyle.cancel, handler: nil))
// show the alert
self.present(alert, animated: true, completion: nil)
}
}
您可能会遇到崩溃,因为您在主线程之外启动UI活动。尝试将UIAlert调用包装到DispatchQueue中,如下所示:
func showAlert(title: String, message : String, buttonTitle1: String, buttonTitle2: String,window: UIWindow){
DispatchQueue.main.async {
// create the alert
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
// add the actions (buttons)
alert.addAction(UIAlertAction(title: buttonTitle1, style: UIAlertActionStyle.default, handler: { action in
if let url = URL(string: "tel://\(self.phoneNumber.text)") {
UIApplication.shared.open(url, options: [:])
}
}))
alert.addAction(UIAlertAction(title: buttonTitle2, style: UIAlertActionStyle.cancel, handler: nil))
// show the alert
self.present(alert, animated: true, completion: nil)
}
}
请编辑您的问题并删除与您的问题无关的代码。请指出导致错误的确切行。@rmaddy刚刚更新了代码您设置了断点吗?在页边空白处查找蓝色标志。请编辑您的问题并删除与您的问题无关的代码。请指出导致错误的确切行。@rmaddy刚刚更新了代码您设置了断点吗?在页边空白处寻找一面蓝色的旗帜。感谢您的回复!我尝试过使用它,但错误仍然存在:(感谢您的回复!我尝试过使用它,但错误仍然存在:(