3d Touch Not Available on iPhone 6s+

820 Views Asked by At

I am trying to add 3d touch into my application. I am trying to enable the user to use force touch on a UITableViewCell, like shown in this project. I am running this code:

if traitCollection.forceTouchCapability == UIForceTouchCapability.Available {
    registerForPreviewingWithDelegate(self, sourceView: view)
} else {
    print("unavailable")
}

I have tried running it on an iPhone 6s+, but I receive "unavailable" in my logs. Why can I not use 3d touch on a 3d touch-supported device? Thanks for your help.

1

There are 1 best solutions below

0
On BEST ANSWER

Just found some reference about 3D Touch APIs: according to the 3D Touch APIs documentation, Apple suggested that developers to read forceTouchCapability in traitCollectionDidChange: delegate method.

For example, you may check the value in your view controller using:

override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) {
    super.traitCollectionDidChange(previousTraitCollection)
    switch traitCollection.forceTouchCapability {
    case .Available:
        print("Available")
    case .Unavailable:
        print("Unavailable")
    case .Unknown:
        print("Unknown")
    }
}

Hope it helps.