0

私はXcode 6.0とswiftで作業しています。UIAlertView と UIAlertController (例: 以下の 2 つの関数) は、UIViewController から継承された myViewController では正常に動作しますが、UIInputViewController から継承された KeyboardViewController ではクラッシュします。Apple はカスタム キーボードでアラートビューを許可していませんか、それともコーディングに誤りがありますか? どんな回答でも大歓迎です。

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)
4

2 に答える 2

0

それがSwiftの誰かを助けることができることを願っています:

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 と拡張機能の両方でこのファイルをコンパイルできます。

于 2015-12-27T13:46:09.043 に答える
0

iOS 8 から、新しいマクロがあります。

NS_EXTENSION_UNAVAILABLE_IOS

iOS では一部のクラスの使用が許可されていませんEXTENSION

iOS での使用が許可されていないか、AlertViewまたはAlertControllerビルドしている場合CUSTOM KEYBOARD EXTENSION

続きを見る:

于 2014-09-30T08:23:53.570 に答える