1.0.5 • Published 8 years ago
catapush_phonegap v1.0.5
Catapush PhoneGap / Cordova / Ionic Library
Introduction
Set of tools to easily implement Catapush in your PhoneGap / Cordova / Ionic hybrid project.
Download
The library can be downloaded here: full version, minified version. If you are using npm (package.json) you can install it with:
npm install catapush_phonegap
Usage
Load the library and its dependencies:
<link type="text/css" href="catapush-widget.css" rel="stylesheet">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/strophe.js/1.2.6/strophe.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/ydn.db/0.9.2/ydn.db-isw-core-qry.js"></script>
<script type="text/javascript" src="catapush.js"></script>
<script type="text/javascript" src="catapush-widget.js"></script>
<script type="text/javascript" src="catapush-phonegap.js"></script>
create a div container
<div id="catapush-widget"></div>
Load the widget, the library and connect using an existing Catapush user:
var catapush = Catapush.get();
$('#catapush-widget').catapushWidget({
'appKey': 'yourAppKey',
'platform' : Catapush.PLATFORM.ANDROID, // Platform as defined in Catapush Library
'user' : 'userIdentifier',
'password' : 'userPassword',
'instance': this.catapush
});
CatapushPhonegap.start(this.catapush);
Use the api provided by the library to add notification handlers and more.
API
Functions
- getPlatformId - obtain current platform id as required by Catapush Api
- updateToken (token) - update current push token using Catapush API
- setupPush - setup Push notification through plugin phonegap-plugin-push
- getOnForeground - returns true if app is currently in foreground
- alert (message) - show simple alerts, using Toastr when possible
- starts - starts the plugin
- attachment - handlers used to store and read attachments, can be used to set jquery widget handlers
Events
- onShow - triggered when application is put on foreground
- onHide - triggered when application is removed from foreground (closed or hidden)
Dependencies
The app depends on four libraries:
- jQuery - v. 1.7.0 and higher - a fast, small, and feature-rich JavaScript library;
- Strophe.js - v. 1.2.6 and higher - an XMPP library for JavaScript. Its primary purpose is to enable web-based, real-time XMPP applications that run in any browser;
- ydn-db - v. 0.9.2 and higher - Javascript database library for IndexedDB, WebSQL and WebStorage;
- catapush - v. 0.1 and higher - Main Catapush Library;
- catapush jquery widget - v. 0.1 and higher - Catapush jQuery Widget.
Can also been installed using npm (package.json):
..
"dependencies": {
"jquery": "*",
"strophe.js": "*",
"ydn.db": "*",
"catapush": "*",
"catapush_widget": "*"
},
..
Catapush Widget is not mandatory, but represents an easy way to show messages.
Some cordova packages are also needed:
- phonegap-plugin-push - v. 1.7 and higher - used to support push notifications, Catapush version is suggested due to some bugfixes;
- cordova-plugin-x-toast - v. 2.5 and higher - show nice toastr messages;
- cordova-plugin-device - v. 1.1 and higher - detect current device;
- cordova-plugin-whitelist - v. 1.2 and higher - whitelist external api services;
- cordova plugin add cordova-plugin-file - v. 4 and higher - store and read files, used for attachments (optional);
- cordova plugin add cordova-plugin-file-opener2 - v. 2 and higher - open file with the correct app (optional).