How to make iPhone vibrate using Swift?

后端 未结 11 1536
天命终不由人
天命终不由人 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:23

    Swift 4.2, 5.0

     if #available(iOS 10.0, *) {
          UIImpactFeedbackGenerator(style: .light).impactOccurred()
       } 
    

    You can also choose other styles like

        style: .heavy
        style: .medium
    
        //Note: soft and rigid available in only iOS 13.0
        style: .soft
        style: .rigid
    

提交回复
热议问题