Is it possible to create custom vibration pattern for the user notification alert? example, we can choose to have different audio for the user notification. Is it possible to have custom vibration pattern as well?
I mean do this programmatically on iOS using swift.
For create custom vibrations in iOS. Use AudioServicesPlaySystemSoundWithVibration and AudioServicesStopSystemSound.
Heart Beat Vibration Example
But only call this (AudioServicesPlaySystemSoundWithVibration ) will make a vibration never stop. So I have to found some function to stop it.
The answer is
AudioServicesStopSystemSound
. It's also a private function in AudioToolbox framework.The declaration of the function is like
NOTE:
AudioServicesPlaySystemSoundWithVibration
is only available on iOS6There is currently no public available API in iOS 9 and iOS 9.1.
And In iOS 10 there's a new API called
UIFeedbackGenerator
. See this post for more details. It only works on the iPhone 7 and iPhone 7 Plus for now.Disclaimer: There is a way to interact with Taptic Engine (iOS 9) directly, but there is a private method. You should not use it in App Store applications.
You can try this. In the below code you can get different types of vibrations with audio and without audio. make sure that you have imported these (import AudioToolbox, import AVFoundation)