Native plugin wrappers for Cordova and Ionic with TypeScript, ES6+, Promise and Observable support
npx @tessl/cli install tessl/npm-ionic-native@2.9.0Ionic Native provides a comprehensive collection of TypeScript wrappers for Cordova plugins, enabling native mobile functionality in Ionic, Cordova, and web view applications. It standardizes native functionality access through Promise and Observable interfaces while maintaining compatibility with both Angular 1 and Angular 2+ applications.
npm install ionic-nativeimport { Camera, Device, Geolocation } from 'ionic-native';For CommonJS:
const { Camera, Device, Geolocation } = require('ionic-native');Browser global access:
// Available as window.IonicNative after including the bundle
window.IonicNative.Camera.getPicture(options);import { Camera, CameraOptions } from 'ionic-native';
// Configure camera options
const options: CameraOptions = {
quality: 100,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMERA,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 300,
targetHeight: 300
};
// Take a picture
Camera.getPicture(options).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
let base64Image = 'data:image/jpeg;base64,' + imageData;
}, (err) => {
// Handle error
});Ionic Native is built around several key architectural patterns:
Core device information and system capabilities for identifying device characteristics and platform details.
class Device {
static cordova: string;
static model: string;
static platform: string;
static uuid: string;
static version: string;
static manufacturer: string;
static isVirtual: boolean;
static serial: string;
}
class AppVersion {
static getAppName(): Promise<string>;
static getPackageName(): Promise<string>;
static getVersionCode(): Promise<string | number>;
static getVersionNumber(): Promise<string>;
}Comprehensive camera functionality, media capture, and photo/video management with full configuration options.
interface CameraOptions {
quality?: number;
destinationType?: number;
sourceType?: number;
allowEdit?: boolean;
encodingType?: number;
targetWidth?: number;
targetHeight?: number;
mediaType?: number;
correctOrientation?: boolean;
saveToPhotoAlbum?: boolean;
cameraDirection?: number;
popoverOptions?: CameraPopoverOptions;
}
class Camera {
static getPicture(options?: CameraOptions): Promise<any>;
static cleanup(): Promise<any>;
static DestinationType: {
DATA_URL: 0;
FILE_URI: 1;
NATIVE_URI: 2;
};
static EncodingType: {
JPEG: 0;
PNG: 1;
};
}File system operations, database access, and secure storage solutions for mobile app data persistence.
class File {
static applicationDirectory: string;
static dataDirectory: string;
static cacheDirectory: string;
static externalDataDirectory: string;
static createFile(path: string, fileName: string, replace: boolean): Promise<FileEntry>;
static writeFile(path: string, fileName: string, text: string | Blob | ArrayBuffer, options: IWriteOptions): Promise<any>;
static readAsText(path: string, file: string): Promise<string>;
static removeFile(path: string, fileName: string): Promise<RemoveResult>;
}
class SQLite {
static create(config: any): SQLiteObject;
}HTTP requests, network status monitoring, and in-app browser functionality for connected applications.
interface HTTPResponse {
status: number;
data?: any;
headers: any;
url: string;
}
class HTTP {
static get(url: string, parameters: any, headers: any): Promise<HTTPResponse>;
static post(url: string, body: any, headers: any): Promise<HTTPResponse>;
static put(url: string, body: any, headers: any): Promise<HTTPResponse>;
static delete(url: string, parameters: any, headers: any): Promise<HTTPResponse>;
}
class Network {
static type: string;
static onConnect(): Observable<any>;
static onDisconnect(): Observable<any>;
}Geolocation services, background location tracking, and geofencing capabilities for location-aware applications.
interface GeolocationOptions {
enableHighAccuracy?: boolean;
timeout?: number;
maximumAge?: number;
}
interface Geoposition {
coords: Coordinates;
timestamp: number;
}
class Geolocation {
static getCurrentPosition(options?: GeolocationOptions): Promise<Geoposition>;
static watchPosition(options?: GeolocationOptions): Observable<Geoposition>;
}Push notifications, local notifications, dialogs, and UI interaction components for user engagement.
interface ILocalNotification {
id?: number;
title?: string;
text?: string;
every?: string;
at?: Date;
data?: any;
}
class LocalNotifications {
static schedule(options?: ILocalNotification | ILocalNotification[]): void;
static clear(notificationId: number): Promise<boolean>;
static on(eventName: string): Observable<any>;
}
class Toast {
static show(message: string, duration: string, position: string): Promise<any>;
static showShortTop(message: string): Promise<any>;
}Access to device sensors including accelerometer, gyroscope, compass, battery status, and vibration.
interface Acceleration {
x: number;
y: number;
z: number;
timestamp: number;
}
class DeviceMotion {
static getCurrentAcceleration(): Promise<Acceleration>;
static watchAcceleration(options?: AccelerometerOptions): Observable<Acceleration>;
}
class Vibration {
static vibrate(time: number | number[]): void;
}Social media integration, content sharing, and authentication for Facebook, Google+, and Twitter platforms.
class SocialSharing {
static share(message?: string, subject?: string, file?: string | string[], url?: string): Promise<any>;
static shareViaEmail(message: string, subject: string, to: string[], cc?: string[], bcc?: string[], files?: string | string[]): Promise<any>;
static shareViaTwitter(message: string, image?: string, url?: string): Promise<any>;
}
interface FacebookLoginResponse {
status: string;
authResponse: {
userID: string;
accessToken: string;
};
}
class Facebook {
static login(permissions: string[]): Promise<FacebookLoginResponse>;
}Biometric authentication, secure storage, and device security features for protecting user data.
class TouchID {
static isAvailable(): Promise<string>;
static verifyFingerprint(message: string): Promise<any>;
}
interface FingerprintOptions {
clientId: string;
clientSecret: string;
disableBackup?: boolean;
}
class FingerprintAIO {
static isAvailable(): Promise<any>;
static show(options: FingerprintOptions): Promise<any>;
}Barcode scanning, NFC communication, keyboard management, and hardware interaction capabilities.
interface BarcodeScannerOptions {
preferFrontCamera?: boolean;
showFlipCameraButton?: boolean;
showTorchButton?: boolean;
torchOn?: boolean;
prompt?: string;
resultDisplayDuration?: number;
formats?: string;
orientation?: string;
disableAnimations?: boolean;
disableSuccessBeep?: boolean;
}
interface BarcodeScanResult {
text: string;
format: string;
cancelled: boolean;
}
class BarcodeScanner {
static scan(options?: BarcodeScannerOptions): Promise<BarcodeScanResult>;
}App analytics, advertising integration, and monetization features for tracking user behavior and revenue generation.
interface AdMobOptions {
bannerId?: string;
interstitialId?: string;
rewardVideoId?: string;
isTesting?: boolean;
autoShow?: boolean;
}
class AdMob {
static createBanner(adIdOrOptions: string | AdMobOptions): Promise<any>;
static showInterstitial(): Promise<any>;
}
class GoogleAnalytics {
static startTrackerWithId(id: string): Promise<any>;
static trackView(title: string): Promise<any>;
static trackEvent(category: string, action: string, label?: string, value?: number): Promise<any>;
}interface PluginConfig {
pluginName: string;
plugin: string;
pluginRef: string;
repo: string;
install?: string;
platforms?: string[];
}
interface CordovaOptions {
sync?: boolean;
observable?: boolean;
callbackOrder?: 'reverse';
callbackStyle?: 'node' | 'object';
successIndex?: number;
errorIndex?: number;
platforms?: string[];
}
// TypeScript decorators for plugin method wrapping
function Plugin(config: PluginConfig): ClassDecorator;
function Cordova(opts?: CordovaOptions): MethodDecorator;
function CordovaInstance(opts?: any): MethodDecorator;
function CordovaProperty(target: any, key: string): void;// Core utility types used across plugins
interface RemoveResult {
success: boolean;
fileRemoved: Entry;
}
interface Entry {
isFile: boolean;
isDirectory: boolean;
name: string;
fullPath: string;
}
interface FileEntry extends Entry {
file(successCallback: (file: File) => void, errorCallback?: (error: FileError) => void): void;
}
interface DirectoryEntry extends Entry {
createReader(): DirectoryReader;
getFile(path: string, options?: Flags, successCallback?: (entry: FileEntry) => void, errorCallback?: (error: FileError) => void): void;
getDirectory(path: string, options?: Flags, successCallback?: (entry: DirectoryEntry) => void, errorCallback?: (error: FileError) => void): void;
}
// Promise/Observable type patterns
type CordovaPromise<T> = Promise<T>;
type CordovaObservable<T> = Observable<T>;