This tutorial shows how to add the Vibration service to an AngularJS app.
Apache Cordova (PhoneGap) is automatically included when you create a new project in Appery.io. The Vibration component used in Appery.io is the Vibration component from Apache Cordova.
Note that the option of creating new apps with the Ionic framework was removed but we still support the projects that were created with it earlier.
- Open your Appery.io Bootstrap/AngularJS or Ionic/AngularJS project or create a new one. You will get two default pages: index and Screen1.
- Go to Screen1 and add a Button component to the page, with its Text = Vibro and ng-click = vib().
Now, let’s create services and variables and bind them with UI components.
- First, go to SCOPE and add a Vibration plugin for Android: in the builder, go to Project > CREATE NEW > From Plugin.
- Select Apperyio Vibration Service and click Import selected plugins.
- 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 function – vib and click Edit, opening the function editor.
- Next, use the snippet Invoke service: from the drop-down, select Invoke service, delete the text “service_name” in the code and click CTRL+SPACE to get the drop-down with all the available services.
Instead of invoking services in the code editor with subsequent auto completing, you can use a drag and drop feature to invoke services.
- Select Notification_vibrate service. After auto completing, the service is added to the function code and you can click Mapping to map the service to the page.
The click on the upper mapping button defines the service request, the lower one – the service response:
There are no response parameters, and the only optional request parameter – duration. It is set in milliseconds and by default it equals 2000. Please find more here.
Testing the app should be done on the device.
Testing on Android is relatively simple, since you can quickly install any app on your device.
To do it, build the Android binary and install it on 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.
Build the app and install it on your device.
Please, note that to export the app for iOS, you will need to upload your distribution certificate and provisioning profile obtained from Apple under the App settings > iOS binary tab.
You can check this document in case you need help with exporting your application for iOS. Here, you will find the document that explains how to manage certificates in Appery.io.
Updated 24 days ago