forceTouchCapability not available for some UIViewControllers in viewDidLoad

Environment is iOS 12.4.1 on iPhoneXs

XCode 11.1, simulator IOS 13.1


I am implementing peekView in a VC.

I registerForPreviewing in viewDidLoad as advised.

        if traitCollection.forceTouchCapability == .available {
            registerForPreviewing(with: self, sourceView: view)
        }


This works OK on simulator.

But on device, register is not called.

I tested traitCollection.forceTouchCapability : .unknown.


What is surprising:

- it works on simulator

- if I move this code to viewWillAppear, it works OK

- I have the similar code in a TableViewController: it works within viewDidLoad


I noted that registerForPreviewing is deprecated, but that should not prevent traitCollection.forceTouchCapability to be .available.


In such a case, do I need to unregister manually to avoid multiple registrations ? Or can I trust bthe system to do it for me ?

Accepted Reply

So, as this works in viewWillAppear, I'll close the thread.

Replies

So, as this works in viewWillAppear, I'll close the thread.