【问题标题】:iOS swift custom keyboard no sound and delayiOS swift自定义键盘没有声音和延迟
【发布时间】:2014-12-29 00:46:48
【问题描述】:

我正在 iOS 上使用新语言 swift 测试键盘扩展,但我无法为 keyPressed 事件播放声音,并且有延迟,大约 10 秒当我单击键时。

这是我的代码:

@IBAction func keyPressed(button: UIButton) {
    var string = button.titleLabel!.text
    (textDocumentProxy as UIKeyInput).insertText("\(string!)")
    AudioServicesDisposeSystemSoundID(1104)
    AudioServicesPlaySystemSound(1104)
    UIView.animateWithDuration(0.2, animations: {
        button.transform = CGAffineTransformScale(CGAffineTransformIdentity, 2.0, 2.0)
        }, completion: {(_) -> Void in
            button.transform =
            CGAffineTransformScale(CGAffineTransformIdentity, 1, 1)
    })
}

提前感谢您的任何意见或建议...

【问题讨论】:

标签: ios xcode swift custom-keyboard ios8-extension


【解决方案1】:

您需要在另一个线程中播放声音。用户需要允许完全访问才能使其正常工作。因此,请确保您在扩展程序的 info.plist 中请求此内容

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),     
{
    AudioServicesPlaySystemSound(1104);
});    

对于 Objective-C,只需在 {

前面添加 ^ 符号

【讨论】:

    【解决方案2】:

    您需要将AudioServicesDisposeSystemSoundID(1104) 移动到deinit 方法。

    【讨论】:

      猜你喜欢
      • 2015-06-14
      • 2015-07-09
      • 1970-01-01
      • 2015-12-21
      • 1970-01-01
      • 2018-04-03
      • 1970-01-01
      • 1970-01-01
      • 2018-05-24
      相关资源
      最近更新 更多