在 UIAlertController 给出 _BSMachError 之后呈现 UIActivityViewController
presenting UIActivityViewController after a UIAlertController gives _BSMachError
我有一个触发 UIActivityViewController 显示的 UIAlertAction。我如何确保 UIAlertController 被关闭,以便在显示 UIActivityViewController 时我不会收到如下所示的错误 _BSMachError。如何从 UIAlertAction 处理程序中正确关闭 UIAlertController?我查看了 SO 上的各种帖子,认为是这个问题导致了错误消息,但当然可能不是!!
第一个 UIAlertController 是:
func presentDone() {
let doneAlert = UIAlertController(title: "Done!",
message: "",
preferredStyle: .Alert)
let sendLater = UIAlertAction(title: "Send Later", style: .Default) {action -> Void in}
let sendCode = UIAlertAction(title: "Send Now", style: .Default, handler: sendCodeAlert)
doneAlert.addAction(sendCode)
doneAlert.addAction(sendLater)
self.presentViewController(doneAlert, animated: true, completion: nil)
}
按下 sendCode 按钮时出现 _BSMachError: (os/kern) invalid capability (20) _BSMachError: (os/kern) invalid name (15)。
func sendCodeAlert(alert: UIAlertAction) {
let message: String = "Hi! Ready to go!"
let postItems: [AnyObject] = [message]
let controller: UIActivityViewController = UIActivityViewController(activityItems: postItems, applicationActivities: nil)
if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.Phone {
self.presentViewController(controller, animated: true, completion: nil)
} else {
let popup: UIPopoverController = UIPopoverController(contentViewController: controller)
popup.presentPopoverFromRect(CGRectMake(self.view.frame.size.width / 2, self.view.frame.size.height / 4,0,0), inView: self.view, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)
}
}
}
感谢任何对此有想法的人。
我总是在多个地方遇到这个错误,但它从来没有造成任何问题。忽略它似乎是安全的。
我给空处理程序的 OK 按钮遇到了几乎完全相同的问题,如下所示:
let okButton = UIAlertAction(title: "OK", style: .Default, handler: { (action) -> Void in
})
当它刚刚显示警报本身时,我已经开始抛出这些警告,但按下 OK 按钮又抛出另一个警告。
首先,我删除了处理程序(将其设置为 nil),因为我一开始什么都没做。这使警告消失了。接下来我做的是尝试查看如何解决问题,然后我再次添加了它。没有更多的错误。
我认为这是一个 Xcode / 调试器 / 编译器问题,但请确保您在启动警报时也处于正确的线程中。在您提交之前始终修复警告,您无法确定其他人不会遇到它,直到您确定它已经消失在您身边。
我有一个触发 UIActivityViewController 显示的 UIAlertAction。我如何确保 UIAlertController 被关闭,以便在显示 UIActivityViewController 时我不会收到如下所示的错误 _BSMachError。如何从 UIAlertAction 处理程序中正确关闭 UIAlertController?我查看了 SO 上的各种帖子,认为是这个问题导致了错误消息,但当然可能不是!!
第一个 UIAlertController 是:
func presentDone() {
let doneAlert = UIAlertController(title: "Done!",
message: "",
preferredStyle: .Alert)
let sendLater = UIAlertAction(title: "Send Later", style: .Default) {action -> Void in}
let sendCode = UIAlertAction(title: "Send Now", style: .Default, handler: sendCodeAlert)
doneAlert.addAction(sendCode)
doneAlert.addAction(sendLater)
self.presentViewController(doneAlert, animated: true, completion: nil)
}
按下 sendCode 按钮时出现 _BSMachError: (os/kern) invalid capability (20) _BSMachError: (os/kern) invalid name (15)。
func sendCodeAlert(alert: UIAlertAction) {
let message: String = "Hi! Ready to go!"
let postItems: [AnyObject] = [message]
let controller: UIActivityViewController = UIActivityViewController(activityItems: postItems, applicationActivities: nil)
if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.Phone {
self.presentViewController(controller, animated: true, completion: nil)
} else {
let popup: UIPopoverController = UIPopoverController(contentViewController: controller)
popup.presentPopoverFromRect(CGRectMake(self.view.frame.size.width / 2, self.view.frame.size.height / 4,0,0), inView: self.view, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)
}
}
}
感谢任何对此有想法的人。
我总是在多个地方遇到这个错误,但它从来没有造成任何问题。忽略它似乎是安全的。
我给空处理程序的 OK 按钮遇到了几乎完全相同的问题,如下所示:
let okButton = UIAlertAction(title: "OK", style: .Default, handler: { (action) -> Void in
})
当它刚刚显示警报本身时,我已经开始抛出这些警告,但按下 OK 按钮又抛出另一个警告。
首先,我删除了处理程序(将其设置为 nil),因为我一开始什么都没做。这使警告消失了。接下来我做的是尝试查看如何解决问题,然后我再次添加了它。没有更多的错误。
我认为这是一个 Xcode / 调试器 / 编译器问题,但请确保您在启动警报时也处于正确的线程中。在您提交之前始终修复警告,您无法确定其他人不会遇到它,直到您确定它已经消失在您身边。