diff --git a/README.md b/README.md index 82b960a..ae7fee2 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Swift original measure project: https://github.com/levantAJ/Measure ## Supported Platforms -- iOS +- iOS (Requires ARKit support iOS 11.3+) ## Installation cordova plugin add https://github.com/robsonala/cordova-plugin-measure @@ -40,9 +40,9 @@ cordova.plugins.measure.start({allowMultiplePoints: true}); Set listener for event from measures ```js -cordova.plugins.arkit.onMeasureUpdate((data) => {}); +cordova.plugins.measure.onMeasureUpdate((data) => {}); -// Example: {"data": "10.00cm"} +// Example: data = {"10.00cm"} ``` ---- @@ -52,16 +52,16 @@ cordova.plugins.arkit.onMeasureUpdate((data) => {}); Set listener when the view is dismissed ```js -cordova.plugins.arkit.onFinish((data) => {}); +cordova.plugins.measure.onFinish((data) => {}); /* Examples: IF allowMultiplePoints == FALSE: -["10.00cm"] +data = "10.00cm" IF allowMultiplePoints == TRUE: -["10.00cm", "20.14cm", ...] +data = ["10.00cm", "20.14cm", ...] */ ``` diff --git a/package.json b/package.json index d146b31..7703711 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-measure", - "version": "1.0.0", + "version": "1.1.0", "description": "Cordova plugin using ARKit(iOS) to calculate distance of real world objects", "cordova": { "id": "cordova-plugin-measure", @@ -16,6 +16,6 @@ "arcore" ], "author": "Robson Alviani ", - "license": "ISC" + "license": "MIT" } \ No newline at end of file diff --git a/plugin.xml b/plugin.xml index c9d396e..bedf027 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + cordova-plugin-measure diff --git a/src/ios/MeasurePlugin+ViewControllerDelegate.swift b/src/ios/MeasurePlugin+ViewControllerDelegate.swift index c39e4da..3ebdfed 100644 --- a/src/ios/MeasurePlugin+ViewControllerDelegate.swift +++ b/src/ios/MeasurePlugin+ViewControllerDelegate.swift @@ -6,18 +6,22 @@ extension MeasurePlugin: ViewControllerDelegate { func closeView() { let data = myViewController.getMeasures(); - + var result: CDVPluginResult + if (!allowMultiple() && data.count > 0) { + result = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: data[0]) + } else { + result = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: data) + } + myViewController.view.removeFromSuperview() self.myViewController = nil - - guard let result = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: data) else { return } + result.setKeepCallbackAs(true) commandDelegate!.send(result, callbackId: finishListenerCallbackId) } func onUpdateMeasure(nodeName: String) { - let data = ["data": nodeName]; - guard let result = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: data) else { return } + guard let result = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: nodeName) else { return } result.setKeepCallbackAs(true) commandDelegate!.send(result, callbackId: measureListenerCallbackId) } @@ -30,4 +34,4 @@ extension MeasurePlugin: ViewControllerDelegate { finishListenerCallbackId = command.callbackId } -} \ No newline at end of file +} diff --git a/www/cordova-plugin-measure.js b/www/cordova-plugin-measure.js index 68dac6a..3d05daa 100644 --- a/www/cordova-plugin-measure.js +++ b/www/cordova-plugin-measure.js @@ -4,14 +4,14 @@ var pluginName = 'MeasurePlugin'; /** * Callback listener for Measure changes */ -exports.onMeasureUpdate = function (success, error) { +exports.onMeasureUpdate = function (success = function(){}, error = function(){}) { exec(success, error, pluginName, 'setMeasureListener'); }; /** * Callback when the view is dismissed */ -exports.onFinish = function (success, error) { +exports.onFinish = function (success = function(){}, error = function(){}) { exec(success, error, pluginName, 'setFinishListener'); };