我正在使用Xcode6.0和swift。UIAlertView和UIAlertController (示例:以下两个函数)在从UIViewController继承的myViewController上工作得很好,但在从UIInputViewController继承的KeyboardViewController上崩溃。Apple不允许在自定义键盘上显示alertview吗?还是我的代码中有任何错误?欢迎并感谢您的回复。
func viewAlert() {
var alertView = UIAlertView() <———
alertView.addButtonWithTitle("Ok")
alertView.title = "title"
alertView.message = "message"
alertView.show()
}
func viewAlert0() {
var alert = UIAlertController() <———
alert.title = "title"
alert.message = "are disabled in your device"
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
} <——— debugger error point:
0x325ca19: calll 0x327e620 ; symbol stub for: pthread_kill
0x325ca1e: movl $0x2710, (%esp)
0x325ca25: calll 0x327ec50 ; symbol stub for: usleep$NOCANCEL
0x325ca2a: movl $0xffffffe7, -0xc(%ebp)
0x325ca31: movl %esi, 0x4(%esp)
0x325ca35: movl $0x0, 0x8(%esp)
0x325ca3d: movl $0x3, (%esp)
0x325ca44: calll 0x327e476 ; symbol stub for: sigprocmask
0x325ca49: ud2 <====== Thread 1 :EXC_BAD_INSTRUCTION(code=EXC_i386_INVOP,subcode=0x0)发布于 2014-09-30 16:23:54
从iOS 8开始,我们有了新的宏:
NS_EXTENSION_UNAVAILABLE_IOSiOS不允许在EXTENSION中使用某些类
如果您正在构建CUSTOM KEYBOARD EXTENSION,则iOS不允许使用AlertView或AlertController
查看更多信息:
发布于 2015-12-27 21:46:09
希望它能帮助斯威夫特的某个人:
假设您有一个必须与iOS和扩展一起使用的库(在可能的情况下,我使用的UIApplication.sharedApplication().keyWindow对扩展不可用)
#if NS_EXTENSION_UNAVAILABLE_IOS
func captureScreen() -> UIImage {
let window = UIApplication.sharedApplication().keyWindow
let scale = UIScreen.mainScreen().scale
UIGraphicsBeginImageContextWithOptions(window!.bounds.size, false, scale)
window?.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let image : UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
#else
#endif使用#ifdef允许我们为iOS和扩展编译这个文件。
https://stackoverflow.com/questions/25079319
复制相似问题