$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
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.