How to make iPhone vibrate using Swift?

后端 未结 11 1540
天命终不由人
天命终不由人 2020-11-29 16:08

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
AudioServicesPl         


        
11条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 16:37

    You can vibrate the phone using either AudioServices or Haptic Feedback.

    // AudioServices
    AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
    
    // Haptic Feedback
    UIImpactFeedbackGenerator(style: .medium).impactOccurred()
    

    Checkout my open source framework Haptica, it supports both Haptic Feedback, AudioServices and unique vibrations patterns. Works on Swift 4.2, Xcode 10

提交回复
热议问题