Appery.io

The Appery.io Developer Hub

Welcome to the Apperyio developer hub. You'll find comprehensive guides and documentation to help you start working with apperyio as quickly as possible, as well as support if you get stuck. Let's jump right in!

Guides    

Camera

Using the Camera service

Introduction

This tutorial shows how to create an AngularJS app that uses the Camera service.

The app will look like:

Apache Cordova (PhoneGap)

Apache Cordova (PhoneGap) is automatically included when you create a new project in Appery.io. The Camera component used in Appery.io is the Camera component from Apache Cordova.

Note

To learn more about the component, and any other settings or options, please see the PhoneGap camera documentation page.

Creating the app

Design

  1. Open your Appery.io Bootstrap & AngularJS or Ionic & AngularJS project or create a new one. You will get two default pages: index and Screen1.

  2. Go to Screen1 and create the following UI consisting of:

    • The Button component. Configure its Text to Camera and ng-click to launchCam();
    • The Image component. Set ng-src = {{im}}.

Now, let’s create services and variables and bind them with UI components.

Scope

  1. First, go to SCOPE and add a variable: im (for image).
  2. Then, to add a Camera plugin for Android: in the builder, go to Project > CREATE NEW > From Plug-in.
  3. In the new window, select Apperyio Camera Service and click “Import selected plug-ins”.
  4. In the Project view, a related service (Camera_getPicture) and a JavaScript file appear.
  5. After a native service has been added to the app, it can be called. Invoking a native service is very similar to invoking a REST service.
    To call the added service, go to the SCOPE view of the Screen1 page, add a new scope function – launchCam and click “Edit”, opening the function editor.
  6. Next, use the snippet Invoke service: click “Invoke service”, delete the text "service_name" in the code and click <CTRL> + <SPACE> to select Camera_getPicture service.

Note

Instead of invoking services in the code editor with subsequent auto completing, you can use a drag and drop feature to invoke services.

After auto completing, the service is added to the function code and you can map the service to the page. The click on the upper mapping button defines the service request, the lower one – the service response.

  1. Optionally, you can use the following parameters to create a request mapping:
    • quality – Quality of the saved image, expressed as a range of 0-100 (information about the camera’s resolution is unavailable).
    • destinationType – Choose the format of the return value.
    • sourceType – Set the source of the picture.
    • allowEdit – Allow simple editing of image before selection.
    • encodingType – Choose the returned image file’s encoding.
    • targetWidth – Width in pixels to scale image (aspect ratio remains constant).
    • targetHeight – Height in pixels to scale image (aspect ratio remains constant).
    • mediaType – Set the type of media to select from (PHOTOLIBRARY or SAVEDPHOTOALBUM).
    • correctOrientation – Rotate the image to correct for the orientation of the device during capture.
    • saveToPhotoAlbum – Save the image to the photo album on the device after capture.
    • popoverOptions – iOS-only options that specify popover location in iPad.
    • cameraDirection – Choose the camera to use (front- or back-facing).

Here is a sample request mapping with the use of some camera service optional parameters:

  1. Now, click success “Mapping” button to map the service to the page and bind the added variable im to image in the service responce, then click “Save and return”:

Note

You will have to notify AngularJS about the need to run update loop using scope method $scope.$apply(); as well. Please find more info about this here).

The result:

var requestData = {};
Apperyio.get("Camera_getPicture")(requestData).then(
function(success){
 
var im_scope = $scope["im"];
im_scope = success.image;
$scope["im"] = im_scope;
 
$scope.$apply(); 
 },
function(error){
  });

Since we’re invoking a native component, this app needs to be tested as a hybrid app, or installed on the device:

Testing options

Android

  1. Use the Appery.io Mobile Tester app. It’s an app that allows you to launch any app created in Appery.io as a hybrid app. You can find it in the Google Play Store.
  2. Build the Android binary and install it your device. When the build is completed, you’ll see a QR code. Scanning the QR code will download the app to your phone. You can also email the app to your device.

iOS

iOS options:

  1. Use the Appery.io Mobile Tester app. It’s an app that allows you to launch any app created in Appery.io as a hybrid app.
  2. Build the app and install it on your device.

iOS Quirks

Since iOS 10 it's mandatory to add a CAMERA_USAGE_DESCRIPTION and PHOTOLIBRARY_USAGE_DESCRIPTION to plugin options.

Before building .ipa file go to App Settings > Cordova plugins and click Options button for Camera plugin.
You should add CAMERA_USAGE_DESCRIPTION and PHOTOLIBRARY_USAGE_DESCRIPTION variables there, otherwise .ipa build process will fail.

Further details can be found at https://docs.appery.io/docs/appexport-ios#section-keys-and-settings

And Cordova GitHub page https://github.com/apache/cordova-plugin-camera#ios-quirks

Camera


Using the Camera service

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.