I need to make the iPhone vibrate, but I don't know how to do that in Swift. I know that in Objective-C, you just write:
import AudioToolbox
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
But that is not working for me.
I need to make the iPhone vibrate, but I don't know how to do that in Swift. I know that in Objective-C, you just write:
import AudioToolbox
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
But that is not working for me.
For iOS 10.0+ You can try UIFeedbackGenerator
Simple viewController above, just replace your view controller in your test "single view app"
Here you will find all codes for each .caf and associated category :
https://github.com/TUNER88/iOSSystemSoundsLibrary
For example if you want a lighter vibration you can use the code 1003.
Good luck and have fun ;)
Swift 4.2 Updated
Just insert code below into your project.
Usage
Source Code
We can do this in Xcode7.1
Other vibration types:
More About Vibration - http://www.mikitamanko.com/blog/2017/01/29/haptic-feedback-with-uifeedbackgenerator/
Now you can just call
UIDevice.vibrate()
as needed.