Has Apple deprecated iPhone 3D touch in Swift?

768 Views Asked by At

I made a game 2 years ago using the 3D touch feature in Swift because it was pretty new but I've never released the game because I got a new contract. Now I have time I want to release it but the code doesn't work any more. (3D touch custom actions, not the peek & pop action)

When I print the touch result, the force value will always return 0.0 like this:

[<UITouch: 0x102613850> phase: Began tap count: 2 force: 0.000 window: <UIWindow: 0x10222bf70; frame = (0 0; 414 896); gestureRecognizers = <NSArray: 0x28011cde0>; layer = <UIWindowLayer: 0x280f41840>> view: <UIView: 0x102083080; frame = (0 82; 414 780); autoresize = RM+BM; gestureRecognizers = <NSArray: 0x2801a0c30>; layer = <CALayer: 0x280f2a540>> location in window: {299.33332824707031, 661.66665649414062} previous location in window: {299.33332824707031, 661.66665649414062} location in view: {299.33332824707031, 579.66665649414062} previous location in view: {299.33332824707031, 579.66665649414062}]

I know Apple is removing this feature from devices cause of the cost but as I remember, the iPhone 11 pro still has it. Does anyone know if this value is deprecated?

1

There are 1 best solutions below

2
On

Every touch starts as a contact with no force at all, as soon as the user's finger makes contact (or even near-contact) with the screen. The force only starts to build as the user's finger is compressed against the screen. UITouch force on touchesBegan is zero


Force Touch

The technology was first unveiled on September 9, 2014, during the introduction of Apple Watch. Starting with the Apple Watch, Force Touch has been incorporated into many products within Apple’s lineup. This notably includes MacBooks and the Magic Trackpad 2. The technology is known as 3D Touch on the iPhone models. source

These devices support Haptic Touch:

  • iPhone 11
  • iPhone 11 Pro
  • iPhone 11 Pro Max
  • iPhone XR

These devices support 3D Touch:

  • iPhone 6s
  • iPhone 6s Plus
  • iPhone 7
  • iPhone 7 Plus
  • iPhone 8
  • iPhone 8 Plus
  • iPhone X
  • iPhone XS
  • iPhone XS Max

Datasource (2020 January) Change 3D or Haptic Touch sensitivity on your iPhone

Solution

Check a presence of 3D Touch on a device

if traitCollection.forceTouchCapability == .available {

}

The iOS trait environment is exposed though the traitCollection property of the UITraitEnvironment protocol. This protocol is adopted by the following classes: UIScreen, UIWindow, UIViewController, UIPresentationController, and UIView. source