简体   繁体   中英

How can you make device vibrate at different frequencies using swift?

I want to make an app that make phone vibrate at different frequencies. How can I control the frequency of the phone vibrating?

I don't know if it helps, but in my case I wanted to have longer vibration for some reasons & I created this extension for it.

extension UIViewController {

    func vibrate(_ style: UIImpactFeedbackGenerator.FeedbackStyle = .heavy) {
        let impactFeedbackgenerator = UIImpactFeedbackGenerator(style: style)
        impactFeedbackgenerator.prepare()
        impactFeedbackgenerator.impactOccurred()
    }

    func vibrateBomb() {
        for i in 0...4 {
            DispatchQueue.main.asyncAfter(deadline: .now() + Double(i * 1)/3) {
                self.vibrate()
            }
            DispatchQueue.main.asyncAfter(deadline: .now() + Double(i * 1)/5) {
                self.vibrate()
            }
            DispatchQueue.main.asyncAfter(deadline: .now() + Double(i * 1)/8) {
                self.vibrate()
            }
        }
    }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM