Skip to content

Commit

Permalink
On Leave should kill Scan and isSupported
Browse files Browse the repository at this point in the history
  • Loading branch information
zfir committed Jun 21, 2024
1 parent 538104d commit a2d4e24
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/ios/CDVRoomPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation
import UIKit
import RoomPlan
import ARKit

@objc(CDVRoomPlan)
class CDVRoomPlan: CDVPlugin, RoomCaptureSessionDelegate, RoomCaptureViewDelegate, UIDocumentPickerDelegate {
Expand Down Expand Up @@ -48,9 +49,17 @@ class CDVRoomPlan: CDVPlugin, RoomCaptureSessionDelegate, RoomCaptureViewDelegat
roomCaptureView.bottomAnchor.constraint(equalTo: viewController.view.bottomAnchor),
roomCaptureView.rightAnchor.constraint(equalTo: viewController.view.rightAnchor)
]);
NotificationCenter.default.addObserver(self, selector: #selector(cancelScanning), name: UIApplication.willResignActiveNotification, object: nil)
startSession()
}

@objc(isSupported:)
func isSupported(command: CDVInvokedUrlCommand) {
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: ARWorldTrackingConfiguration.supportsSceneReconstruction(.mesh))
pluginResult?.keepCallback = true
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
}

private func startSession() {
state = "scanning"
roomCaptureView?.captureSession.run(configuration: roomCaptureSessionConfig)
Expand Down Expand Up @@ -94,6 +103,7 @@ class CDVRoomPlan: CDVPlugin, RoomCaptureSessionDelegate, RoomCaptureViewDelegat
self.activityIndicator?.stopAnimating()
stopSession()
roomCaptureView.removeFromSuperview()
NotificationCenter.default.removeObserver(self)
let result = ["message": "Scanning cancelled"]
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: result)
pluginResult?.keepCallback = true
Expand Down
15 changes: 10 additions & 5 deletions www/CDVRoomPlan.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
var exec = require('cordova/exec');
var exec = require("cordova/exec");

exports.openRoomPlan = function(success, error) {
console.log("CDVRoomPlan.js: openRoomPlan");
exec(success, error, "CDVRoomPlan", "openRoomPlan", []);
};
exports.openRoomPlan = function (success, error) {
console.log("CDVRoomPlan.js: openRoomPlan");
exec(success, error, "CDVRoomPlan", "openRoomPlan", []);
};

exports.isSupported = function (success, error) {
console.log("CDVRoomPlan.js: isSupported");
exec(success, error, "CDVRoomPlan", "isSupported", []);
}

0 comments on commit a2d4e24

Please sign in to comment.