1
votes

Vertical place detection in ARKit is not very good so I am using proximity sensor to place found vertical plane. The UX is as follows:

  1. Ask user to place front of the device on the wall
  2. When the proximity sensor is triggered make a vertical plane using AR Camera transform

The issue that I am currently facing is that when front sensor is triggered, everything comes to a halt. All the CoreMotion sensors and render methods for ARSCNViewDelegate calls stop. This causes the world origin to move from its origin point and make the placed item also move with it.

Is there a way to get proximity sensor data without shutting down everything? Is there a better way to place vertical items?

1

1 Answers

0
votes

Asynchronous functions let you perform two or more tasks almost simultaneously, without waiting until the dispatched block is executed.

So, you have to use an approach like this:

class ViewController: UIViewController {

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        DispatchQueue.main.async {
            self.proximitySensorActivation()
        }
    }

    func proximitySensorActivation() {

        let device = UIDevice.current
        device.isProximityMonitoringEnabled = true

        if device.isProximityMonitoringEnabled {
            NotificationCenter.default.addObserver(self,
                                               selector: #selector(proximityChanged),
                                                   name: UIDevice.proximityStateDidChangeNotification,
                                                 object: device)
        }
    }

    @objc func proximityChanged(notification: NSNotification) {

        if let device = notification.object as? UIDevice {
            print(device)
        }
    }
}