kelin
kelin

Reputation: 11975

Determine 3D touch availability for the device

I want to know if the device supports 3D Touch. I don't like to use the forceTouchCapability property of the UITraitCollection, because it may return unavailable for iPhone 6s if the user has turned off 3D Touch in the settings.

I want to know if 3D Touch is available by hardware, regardless to the settings. The only possible solution which I see is to check device's model. But, may be, someone can suggest more stable and simple solution.

Background: I have added Home Screen Actions to the app, and I want to notify user about it, only if the device supports them.

Upvotes: 3

Views: 357

Answers (1)

Ahmad F
Ahmad F

Reputation: 31645

I am afraid you won't be able to check the exact feature that you are asking for, checking the availability of 3d touch is not only related to the device model:

Keys that indicate the availability of 3D Touch on a device. Only certain devices support 3D Touch. On those that do, the user can disable 3D Touch in the Accessibility area in Settings.

UIForceTouchCapability

Meaning that the system tells your application that the 3d touch is unavailable, regardless whether the device does support 3d touch or not, which explain what you mentioned:

I don't like to use the forceTouchCapability property of the UITraitCollection, because it may return unavailable for iPhone 6s if the user has turned off 3D Touch in settings.

However, you are able to detect changes to 3D Touch availability while your app is running, by implementing traitCollectionDidChange(_:) as mentioned in Checking the Availability of 3D Touch article:

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

Regarding to:

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

Personally, I think it doesn't make sense to do such a thing, because -as I mentioned above- it is controlled by the system; At some point, it won't make a difference whether the device not support 3d touch or if the use disabled the 3d touch, it should leads the the same result referring to your app.

Upvotes: 1

Related Questions