1

I want to make a button that you press and your phone vibrates. When you release, the vibration should stop. Ideally, it will have touch sensitivity, so the harder you press, the stronger the buzz.

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)

Currently this just plays 1 buzz, and a loop still has a slight disconnect, but a loop is still an unwanted workaround.

rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

0

Apparently, you can make the phone vibrate with:

import UIKit
import AudioToolbox

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))            
    }

}

(This example is from a post here)

If you wanted vibration to be indefinite and continuous, you could use timers to play it in sequence. But apparently, this is a common cause of app rejection from the App store, so I wouldn't recommend it.

I'm not sure if there's an API for increasing the velocity of haptic feedback/system vibrate.

jake
  • 1,226
  • 8
  • 14
  • I've tried a loop, but it takes a pause between repeating vibrations. kSystemSoundID_Vibrate does like a half second vibration. I have seen it will likely get rejected, however, I am still curious. – Max Mendelson Jun 08 '19 at 03:51