Ionic ios access to it's plugins


#1

Hi there. I have made an app for ios and installed in my iphone. It has Camera plugin in it. It works perfect in android.

Also in iphone, as I run ionic view app (downloaded from appstore) it works perfect into that (first my phone asks about allowing access to camera), But not working in my own app.

In ionic view app :

enter image description here

But in my own app, Nothing! Doesn’t work. Even auto rotation just works in ionic view app.

Any idea?

EDIT: My impelmentation code:

$scope.takePhoto = function() {
  var options = {
      destinationType: Camera.DestinationType.FILE_URI,
      sourceType: Camera.PictureSourceType.CAMERA,
    };

    $cordovaCamera.getPicture(options).then(function(imageURI) {
    }, function(err) {
      // error
      $scope.camErr = err;
    });
}
$scope.getPhoto = function() {
  var options = {
      destinationType: Camera.DestinationType.PHOTOLIBRARY,
      sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
    };

    $cordovaCamera.getPicture(options).then(function(imageURI) {
    }, function(err) {
      // error
      $scope.camErr = err;
    });
}

#2

Since iOS 10 it’s mandatory to add a NSCameraUsageDescription entry in the info.plist.

The ionic View probably already had this thats why it works on there


#3

So , what should I do? Any more explanation?


#4

check out the plugin doc: https://github.com/apache/cordova-plugin-camera#ios-quirks

and also have a look at this native plugin: https://www.npmjs.com/package/cordova.plugins.diagnostic

it could help with permission issues!


#5

@fishgrind

I installde diagnostic plugin. But the same issue. Then uninstalled camera plugin and installed again with this command:

cordova plugin add cordova-plugin-camera --variable CAMERA_USAGE_DESCRIPTION="your usage message"

Again the same issue.


#6

Finally I found the solution :relaxed:

Just add --save after installing a plugin. For example:

cordova plugin add cordova-plugin-camera --save

As in ionic package docs says:

Cordova plugins may be installed locally, they may not be defined explicitly in your config.xml. To ensure that the build servers know about which plugins you need, use the --save flag when adding and removing plugins.


#7

Just as a heads up, while the above solution is correct, I thought I might add a bit more. I migrated my app from ionic.RC0 to RC1 and found this issue. In order to solve it, I needed to complete two steps.

ionic plugin remove --force cordova-plugin-camera

I had to force removal of the camera plugin, because it was automatically included. Secondly, I had to do this:

ionic plugin add cordova-plugin-camera --variable CAMERA_USAGE_DESCRIPTION="Message" --variable PHOTO_USAGE_DESCRIPTION="Message2" --save

Because you needed both NSCameraUsageDescription and NSPhotoLibraryUsageDescriptionentry in your info.plist file for ios 10.

EDIT: I also had to delete and re-build the project, as it still wasnt accepting the variables during the build. You can also hand modify these in xcode.

Hope this helps.