Determining whether 3D touch is available for a device

I want to know if the device supports 3D Touch. I don't like using the forceTouchCapability

property UITraitCollection

because it can return unavailable

for iPhone 6s if the user has disabled 3D Touch in the settings.

I want to know if 3D Touch is available in hardware regardless of the settings. The only possible solution I see is to check the device model. But maybe someone can suggest a more stable and simpler solution.

Background: I've added Home Screen Actions to the app and I only want to inform the user about it if the device supports them.

+3


source to share


1 answer


I'm afraid you won't be able to test the exact function you are asking for, the 3d touch accessibility check is not only related to the device model:

Keys that indicate 3D Touch is available on the device. Only some devices support 3D Touch. On those that do, the user can turn off the 3D touch in the accessibility area in the settings .

UIForceTouchCapability

Assuming the system is telling your app that 3D touch is not available, whether the device supports 3D touch or not, explains what you mentioned:

I don't like using the forceTouchCapability

UITraitCollection property because it might return unavailable for iPhone 6s if the user has disabled 3D Touch in the preferences.

However, you can detect changes in 3D Touch availability while your application is running by implementing traitCollectionDidChange (_ :) as stated in Checking 3D Touch Availability :



override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
    // Update the app 3D Touch support.
    if self.traitCollection.forceTouchCapability == .available {
        // Enable 3D Touch features
    } else {
        // Fall back to other non 3D Touch features.
    }
}

      

Concerning:

The only possible solution I see is to check the device model

Personally, I think it makes no sense to do this, because, as I mentioned above, it is controlled by the system; At some point it won't matter if the device doesn't support 3D touch or if usage is disabled by 3D touch, it should produce the same result for your application.

0


source







All Articles