DeviceKit icon indicating copy to clipboard operation
DeviceKit copied to clipboard

Detect if device able to produce haptic feedback, Taptic feedback or not

Open Sergozh opened this issue 6 years ago • 4 comments

Could you add bool vars such as hasTapticEngine and hasHapticFeedback? Thank you.

Sergozh avatar Jan 14 '20 11:01 Sergozh

I just played around with the haptics engine myself and thought it would be a great feature. @Zandor300 what do you think?

denisenepraunig avatar Jan 19 '20 08:01 denisenepraunig

Just ran into the issue of not knowing whether a device has haptic feedback. I second the vote for hasHapticFeedback. I'd really like to call that so I'd know whether this will work or not: UIImpactFeedbackGenerator(style: .medium).impactOccurred() // Does nothing on old devices

Many thanks

Multiforge avatar Mar 27 '20 00:03 Multiforge

So this is the short snippet of how I want to check it:

    /// All Taptic Engine Capable Devices
    public static var allTapticEngineCapableDevices: [Device] {
        return [.iPhone6s, .iPhone6sPlus, .iPhone7, .iPhone7Plus, .iPhone8, .iPhone8Plus, .iPhoneX, .iPhoneXR, .iPhoneXS, .iPhoneXSMax, .iPhone11, .iPhone11Pro, .iPhone11ProMax]
    }
    
    /// All Haptic Feedback Capable Devices
    public static var allHapticFeedbackCapableDevices: [Device] {
        return [.iPhone7, .iPhone7Plus, .iPhone8, .iPhone8Plus, .iPhoneX, .iPhoneXR, .iPhoneXS, .iPhoneXSMax, .iPhone11, .iPhone11Pro, .iPhone11ProMax]
    }
    
    public var hasTapticEngine: Bool {
        return isOneOf(Device.allTapticEngineCapableDevices)
    }
    
    var hasHapticFeedback: Bool {
        return isOneOf(Device.allHapticFeedbackCapableDevices)
    }

Sergozh avatar Mar 27 '20 09:03 Sergozh

Apparently there are also two versions of the Taptic Engine, where version two has additional capabilities. https://stackoverflow.com/a/42057620

Shockah avatar Mar 27 '20 09:03 Shockah