$cordovaBarcodeScanner.scan is not a function

  • 1
  • Problem
  • Updated 5 years ago
  • Not a Problem
Hi

I am looking to integrate BarCode scanner plugin "phonegap-plugin-barcodescanner" in my existing ios project. Plugin has been installed successfully but when I am calling scan() method. It is throwing an error

Error: $cordovaBarcodeScanner.scan is not a function. (In '$cordovaBarcodeScanner.scan()', '$cordovaBarcodeScanner.scan' is undefined)

Although Object.getOwnPropertyNames($cordovaBarcodeScanner) method returning "encode,decode". I do not understand where is scan() method gone.

Plugin working fine in newly created project not in my existing project. What could be possible reason please?

thanks

Yousuf
Photo of Yousuf Qureshi

Yousuf Qureshi

  • 8 Posts
  • 0 Reply Likes

Posted 5 years ago

  • 1
Photo of Amir

Amir

  • 8261 Posts
  • 263 Reply Likes
You can share your config.xml or part of the codes here so community can have a look at it.

Surround it with <code></code> tag.

Thanks.
Photo of Yousuf Qureshi

Yousuf Qureshi

  • 8 Posts
  • 0 Reply Likes
Please find config.xml and my code snippet below



<?xml version='1.0' encoding='utf-8'?>
<widget id="com.indivirtual.pmo" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<preference name="AllowInlineMediaPlayback" value="false" />
<preference name="BackupWebStorage" value="cloud" />
<preference name="DisallowOverscroll" value="false" />
<preference name="EnableViewportScale" value="false" />
<preference name="KeyboardDisplayRequiresUserAction" value="true" />
<preference name="MediaPlaybackRequiresUserAction" value="false" />
<preference name="SuppressesIncrementalRendering" value="false" />
<preference name="GapBetweenPages" value="0" />
<preference name="PageLength" value="0" />
<preference name="PaginationBreakingMode" value="page" />
<preference name="PaginationMode" value="unpaginated" />
<feature name="LocalStorage">
<param name="ios-package" value="CDVLocalStorage" />
</feature>
<icon height="57" src="resources/ios/icon/icon.png" width="57" />
<icon height="114" src="resources/ios/icon/icon@2x.png" width="114" />
<icon height="40" src="resources/ios/icon/icon-40.png" width="40" />
<icon height="80" src="resources/ios/icon/icon-40@2x.png" width="80" />
<icon height="50" src="resources/ios/icon/icon-50.png" width="50" />
<icon height="100" src="resources/ios/icon/icon-50@2x.png" width="100" />
<icon height="60" src="resources/ios/icon/icon-60.png" width="60" />
<icon height="120" src="resources/ios/icon/icon-60@2x.png" width="120" />
<icon height="180" src="resources/ios/icon/icon-60@3x.png" width="180" />
<icon height="72" src="resources/ios/icon/icon-72.png" width="72" />
<icon height="144" src="resources/ios/icon/icon-72@2x.png" width="144" />
<icon height="76" src="resources/ios/icon/icon-76.png" width="76" />
<icon height="152" src="resources/ios/icon/icon-76@2x.png" width="152" />
<icon height="29" src="resources/ios/icon/icon-small.png" width="29" />
<icon height="58" src="resources/ios/icon/icon-small@2x.png" width="58" />
<icon height="87" src="resources/ios/icon/icon-small@3x.png" width="87" />
<splash height="1136" src="resources/ios/splash/Default-568h@2x~iphone.png" width="640" />
<splash height="1334" src="resources/ios/splash/Default-667h.png" width="750" />
<splash height="2208" src="resources/ios/splash/Default-736h.png" width="1242" />
<splash height="1242" src="resources/ios/splash/Default-Landscape-736h.png" width="2208" />
<splash height="1536" src="resources/ios/splash/Default-Landscape@2x~ipad.png" width="2048" />
<splash height="768" src="resources/ios/splash/Default-Landscape~ipad.png" width="1024" />
<splash height="2048" src="resources/ios/splash/Default-Portrait@2x~ipad.png" width="1536" />
<splash height="1024" src="resources/ios/splash/Default-Portrait~ipad.png" width="768" />
<splash height="960" src="resources/ios/splash/Default@2x~iphone.png" width="640" />
<splash height="480" src="resources/ios/splash/Default~iphone.png" width="320" />
<name>PMO Summit</name>
<description>
</description>
<author email="yousuf@indivirtualdubai.com" href="http://indivirtualdubai.com/">
Yousuf Qureshi
</author>
<content src="index.html" />
<access origin="*" />
<preference name="webviewbounce" value="false" />
<preference name="UIWebViewBounce" value="false" />
<preference name="DisallowOverscroll" value="true" />
<preference name="android-minSdkVersion" value="16" />
<preference name="BackupWebStorage" value="none" />
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="500" />
<feature name="Keyboard">
<param name="ios-package" onload="true" value="IonicKeyboard" />
</feature>
<feature name="Console">
<param name="ios-package" value="CDVLogger" />
</feature>
<feature name="NetworkStatus">
<param name="ios-package" value="CDVConnection" />
</feature>
<feature name="SplashScreen">
<param name="ios-package" value="CDVSplashScreen" />
<param name="onload" value="true" />
</feature>
<feature name="Globalization">
<param name="ios-package" value="CDVGlobalization" />
</feature>
<feature name="Device">
<param name="ios-package" value="CDVDevice" />
</feature>
<feature name="LocalNotification">
<param name="ios-package" onload="true" value="APPLocalNotification" />
<param name="onload" value="true" />
</feature>
<feature name="StatusBar">
<param name="ios-package" value="CDVStatusBar" />
<param name="onload" value="true" />
</feature>
<preference name="StatusBarOverlaysWebView" value="false" />
<preference name="StatusBarBackgroundColor" value="#000000" />
<preference name="StatusBarStyle" value="lightcontent" />
<feature name="Geolocation">
<param name="ios-package" value="CDVLocation" />
</feature>
<feature name="Badge">
<param name="ios-package" value="APPBadge" />
</feature>
<feature name="SQLitePlugin">
<param name="ios-package" value="SQLitePlugin" />
</feature>
<feature name="InAppBrowser">
<param name="ios-package" value="CDVInAppBrowser" />
</feature>
<feature name="Toast">
<param name="ios-package" value="Toast" />
</feature>
<feature name="BarcodeScanner">
<param name="ios-package" value="CDVBarcodeScanner" />
</feature>
</widget>



$scope.scanBarcode = function(){

$ionicPlatform.ready(function() {

console.log('Object.getOwnPropertyNames:' + Object.getOwnPropertyNames($cordovaBarcodeScanner) + $cordovaBarcodeScanner);
$cordovaBarcodeScanner.scan().then(function(result) {
// Success! Barcode data is here
$scope.scanResults = "We got a barcode\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n" +
"Cancelled: " + result.cancelled;
}, function(error) {
// An error occurred
$scope.scanResults = 'Error: ' + error;
});
});

};

Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
You can have neither 'splash' elements nor 'feature' elements. Use gap:splash and plugins instead.
See the PGB documentation (link at top of this forum).
Photo of Yousuf Qureshi

Yousuf Qureshi

  • 8 Posts
  • 0 Reply Likes
@Petra V.

I am using ionic framework that build on top of phonegap. These tags are supported in their framework.

My problem is with BarcodeScanner only. Somehow it is not working in my existing project.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
That's because the plugin isn't included.
Look at your Plugins tab at your ap's PGB page. Do you see any plugins listed?
Photo of Yousuf Qureshi

Yousuf Qureshi

  • 8 Posts
  • 0 Reply Likes


cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [
{
"file": "plugins/com.ionic.keyboard/www/keyboard.js",
"id": "com.ionic.keyboard.keyboard",
"clobbers": [
"cordova.plugins.Keyboard"
]
},
{
"file": "plugins/cordova-plugin-console/www/logger.js",
"id": "cordova-plugin-console.logger",
"clobbers": [
"cordova.logger"
]
},
{
"file": "plugins/cordova-plugin-console/www/console-via-logger.js",
"id": "cordova-plugin-console.console",
"clobbers": [
"console"
]
},
{
"file": "plugins/cordova-plugin-network-information/www/network.js",
"id": "cordova-plugin-network-information.network",
"clobbers": [
"navigator.connection",
"navigator.network.connection"
]
},
{
"file": "plugins/cordova-plugin-network-information/www/Connection.js",
"id": "cordova-plugin-network-information.Connection",
"clobbers": [
"Connection"
]
},
{
"file": "plugins/cordova-plugin-splashscreen/www/splashscreen.js",
"id": "cordova-plugin-splashscreen.SplashScreen",
"clobbers": [
"navigator.splashscreen"
]
},
{
"file": "plugins/org.apache.cordova.globalization/www/GlobalizationError.js",
"id": "org.apache.cordova.globalization.GlobalizationError",
"clobbers": [
"window.GlobalizationError"
]
},
{
"file": "plugins/org.apache.cordova.globalization/www/globalization.js",
"id": "org.apache.cordova.globalization.globalization",
"clobbers": [
"navigator.globalization"
]
},
{
"file": "plugins/de.appplant.cordova.plugin.local-notification/www/local-notification.js",
"id": "de.appplant.cordova.plugin.local-notification.LocalNotification",
"clobbers": [
"cordova.plugins.notification.local",
"plugin.notification.local"
]
},
{
"file": "plugins/de.appplant.cordova.plugin.local-notification/www/local-notification-core.js",
"id": "de.appplant.cordova.plugin.local-notification.LocalNotification.Core",
"clobbers": [
"cordova.plugins.notification.local.core",
"plugin.notification.local.core"
]
},
{
"file": "plugins/de.appplant.cordova.plugin.local-notification/www/local-notification-util.js",
"id": "de.appplant.cordova.plugin.local-notification.LocalNotification.Util",
"merges": [
"cordova.plugins.notification.local.core",
"plugin.notification.local.core"
]
},
{
"file": "plugins/cordova-plugin-statusbar/www/statusbar.js",
"id": "cordova-plugin-statusbar.statusbar",
"clobbers": [
"window.StatusBar"
]
},
{
"file": "plugins/cordova-plugin-geolocation/www/Coordinates.js",
"id": "cordova-plugin-geolocation.Coordinates",
"clobbers": [
"Coordinates"
]
},
{
"file": "plugins/cordova-plugin-geolocation/www/PositionError.js",
"id": "cordova-plugin-geolocation.PositionError",
"clobbers": [
"PositionError"
]
},
{
"file": "plugins/cordova-plugin-geolocation/www/Position.js",
"id": "cordova-plugin-geolocation.Position",
"clobbers": [
"Position"
]
},
{
"file": "plugins/cordova-plugin-geolocation/www/geolocation.js",
"id": "cordova-plugin-geolocation.geolocation",
"clobbers": [
"navigator.geolocation"
]
},
{
"file": "plugins/de.appplant.cordova.plugin.badge/www/badge.js",
"id": "de.appplant.cordova.plugin.badge.Badge",
"clobbers": [
"plugin.notification.badge",
"cordova.plugins.notification.badge"
]
},
{
"file": "plugins/cordova-sqlite-storage/www/SQLitePlugin.js",
"id": "cordova-sqlite-storage.SQLitePlugin",
"clobbers": [
"SQLitePlugin"
]
},
{
"file": "plugins/org.apache.cordova.inappbrowser/www/inappbrowser.js",
"id": "org.apache.cordova.inappbrowser.inappbrowser",
"clobbers": [
"window.open"
]
},
{
"file": "plugins/cordova-plugin-x-toast/www/Toast.js",
"id": "cordova-plugin-x-toast.Toast",
"clobbers": [
"window.plugins.toast"
]
},
{
"file": "plugins/cordova-plugin-x-toast/test/tests.js",
"id": "cordova-plugin-x-toast.tests"
},
{
"file": "plugins/net.roughshod.plugins.barcodescanner/www/barcodescanner.js",
"id": "net.roughshod.plugins.barcodescanner.BarcodeScanner",
"clobbers": [
"cordova.plugins.barcodeScanner"
]
},
{
"file": "plugins/cordova-plugin-device/www/device.js",
"id": "cordova-plugin-device.device",
"clobbers": [
"device"
]
}
];
module.exports.metadata =
// TOP OF METADATA
{
"com.ionic.keyboard": "1.0.4",
"cordova-plugin-android-support-v4": "21.0.1",
"cordova-plugin-console": "1.0.1",
"cordova-plugin-network-information": "1.0.1",
"cordova-plugin-splashscreen": "2.1.0",
"cordova-plugin-whitelist": "1.0.0",
"org.apache.cordova.globalization": "0.3.4",
"de.appplant.cordova.plugin.local-notification": "0.8.2-dev",
"cordova-plugin-statusbar": "1.0.1",
"cordova-plugin-geolocation": "1.0.1",
"de.appplant.cordova.plugin.badge": "0.7.1",
"cordova-sqlite-storage": "0.7.11-dev",
"org.apache.cordova.inappbrowser": "0.6.0",
"cordova-plugin-x-toast": "2.2.1",
"net.roughshod.plugins.barcodescanner": "3.0.0",
"cordova-plugin-device": "1.0.1",
"de.appplant.cordova.common.registerusernotificationsettings": "1.0.1"
}
// BOTTOM OF METADATA
});



I installed new plugin ....
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Look at your Plugins tab at your app's PGB page. Do you see any plugins listed?

I am looking to integrate BarCode scanner plugin "phonegap-plugin-barcodescanner" in my existing ios project.
.....which is not listed in your code above. Is it in your config.xml and on said Plugins tab?
Photo of Yousuf Qureshi

Yousuf Qureshi

  • 8 Posts
  • 0 Reply Likes
btw I am facing same problem with new barcode scanner plugin too ... system could not find scan() method
Photo of Yousuf Qureshi

Yousuf Qureshi

  • 8 Posts
  • 0 Reply Likes
I uninstalled phonegap-plugin-barcodescanner plugin and now using net.roughshod.plugins.barcodescanner.BarcodeScanner but having same issue with both plugin ..
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
*sigh*
How can I help you if you refuse to answer my question?
Photo of Yousuf Qureshi

Yousuf Qureshi

  • 8 Posts
  • 0 Reply Likes
Sorry Petra, I am not using PGB page but xcode. I did not use PGB page yet.. first project using phonegap.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
In that case, you're a bit lost.
This is the Phonegap Build forum, the place for developers who don't install plugins, SDK's, Phonegap, etc.
You may probably want to ask your question at the Phonegap Google Group or at Stackoverflow.
Photo of Yousuf Qureshi

Yousuf Qureshi

  • 8 Posts
  • 0 Reply Likes
Sorry Petra, I thought It is general forum. And I really appreciate for your time.