【问题标题】:My swift code won't execute a vibration我的快速代码不会执行振动
【发布时间】:2017-10-10 01:56:47
【问题描述】:

我在 xcode 中制作了一个应用程序,它通过一个按钮永远振动,并通过一个按钮停止,但是当我在我的 iphone 上测试它时它不会振动。帮忙?

var timer: Timer?


@IBAction func button1(_ sender: UIButton) {

    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
    timer?.invalidate()
    timer = Timer.scheduledTimer(timeInterval: 0.0, target: self, selector: Selector(("doaction")), userInfo: nil, repeats: true)

}

@IBAction func button2(_ sender: UIButton) {

    timer?.invalidate()
    timer = nil

}

我也在使用 iphone 7 plus,如果这有什么不同的话。

【问题讨论】:

  • 确定您的手机振动没有设置为关闭?仅在手机震动开启时有效。
  • 如何开启?
  • 设置 -> 声音 -> 你必须在振动

标签: ios iphone swift vibration


【解决方案1】:

AudioServicesPlaySystemSound 替换为AudioServicesPlayAlertSound。另外,请确保您正在导入 AudioToolbox

如果你想使用AudioServicesPlaySystemSound,你必须这样做

AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))

【讨论】:

    猜你喜欢
    • 2019-12-21
    • 1970-01-01
    • 2016-12-21
    • 1970-01-01
    • 1970-01-01
    • 2021-02-19
    • 2014-07-21
    • 2021-07-20
    相关资源
    最近更新 更多