2
votes

I have installed ionic Dev app from the play store on my mobile. And I am able to access application directly on mobile just using:

ionic serve -c

But however, when I am trying to test ionic native feature for e.g Camera on my device, I am getting below error:

 Object(__WEBPACK_IMPORTED_MODULE_0__ionic_native_core__["cordova"]) is not a function. 
(In 'Object(__WEBPACK_IMPORTED_MODULE_0__ionic_native_core__["cordova"])(this, "getPicture", { "callbackOrder": "reverse" }, arguments)', 
'Object(__WEBPACK_IMPORTED_MODULE_0__ionic_native_core__["cordova"])' is an instance of Object)

Stack:

getPicture@http://192.168.100.4:8100/build/vendor.js:129897:138
scan@http://192.168.100.4:8100/build/main.js:44:88
callWithDebugContext@http://192.168.100.4:8100/build/vendor.js:15423:47
dispatchEvent@http://192.168.100.4:8100/build/vendor.js:10329:36
http://192.168.100.4:8100/build/vendor.js:39890:65
onInvokeTask@http://192.168.100.4:8100/build/vendor.js:5076:43
runTask@http://192.168.100.4:8100/build/polyfills.js:3:10844
invokeTask@http://192.168.100.4:8100/build/polyfills.js:3:16801
p@http://192.168.100.4:8100/build/polyfills.js:2:27654
v@http://192.168.100.4:8100/build/polyfills.js:2:27894

I have tried to search for this message, but there is not enough support. And I am also not able to figure out the meaning of the message.

Any suggestion on it?

2

2 Answers

0
votes

Check your project type in ionic.config.json file.

If the type is "ionic-angular", then install 4.x.x version. Example

npm i -s @ionic-native/[email protected]

If the type is "angular", then install 5.x.x

npm i -s @ionic-native/[email protected]

Note:

Add ngx at the end of import only if you are using Angular 6

import { Camera } from '@ionic-native/camera/ngx';

if not remove ngx from the import both in app.module.ts and app.component.ts

import { Camera } from '@ionic-native/camera';
0
votes

I found the issue, I was testing on iPhone and we need to explicitly give settings to allow access to the camera in the config.xml file.

I was able to do so, by adding below lines of code in config.xml file:

<edit-config file="*-Info.plist" mode="merge" target="NSCameraUsageDescription">
    <string>Used to take pictures and Scan QR codes</string>
</edit-config>

I hope this will help others.