devicekit / DeviceKit

DeviceKit is a value-type replacement of UIDevice.
MIT License
4.44k stars 433 forks source link

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

Open Sergozh opened 4 years ago

Sergozh commented 4 years ago

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

denisenepraunig commented 4 years ago

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

Multiforge commented 4 years ago

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

Sergozh commented 4 years ago

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)
    }
Shockah commented 4 years ago

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