cordova.plugins.diagnostic
Version:
Cordova/Phonegap plugin to check the state of Location/WiFi/Camera/Bluetooth device settings.
929 lines (860 loc) • 64.1 kB
JavaScript
/**
* Diagnostic plugin for iOS
*
* Copyright (c) 2015 Working Edge Ltd.
* Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS
**/
var Diagnostic = (function(){
/********************
* Internal functions
********************/
/********************
* Public properties
********************/
var Diagnostic = {};
/**
* Permission states
* @type {object}
*/
Diagnostic.permissionStatus = {
"NOT_REQUESTED": "not_determined", // App has not yet requested this permission
"DENIED_ALWAYS": "denied_always", // User denied access to this permission
"RESTRICTED": "restricted", // Permission is unavailable and user cannot enable it. For example, when parental controls are in effect for the current user.
"GRANTED": "authorized", // User granted access to this permission
"GRANTED_WHEN_IN_USE": "authorized_when_in_use", // User granted access use location permission only when app is in use
"EPHEMERAL": "ephemeral", // The app is authorized to schedule or receive notifications for a limited amount of time.
"PROVISIONAL": "provisional", // The application is provisionally authorized to post non-interruptive user notifications.
"LIMITED": "limited" // The app has limited access to the Photo Library
};
Diagnostic.cpuArchitecture = {
UNKNOWN: "unknown",
ARMv6: "ARMv6",
ARMv7: "ARMv7",
ARMv8: "ARMv8",
X86: "X86",
X86_64: "X86_64"
};
/*****************************
*
* Protected member functions
*
****************************/
Diagnostic._ensureBoolean = function (callback){
return function(result){
callback(!!result);
}
};
/**********************
*
* Public API functions
*
**********************/
/***********
* Core
***********/
/**
* Enables debug mode, which logs native debug messages to the native and JS consoles.
* Debug mode is initially disabled on plugin initialisation.
*
* @param {Function} successCallback - The callback which will be called when enabling debug is successful.
*/
Diagnostic.enableDebug = function(successCallback) {
return cordova.exec(successCallback,
null,
'Diagnostic',
'enableDebug',
[]);
};
/**
* Switch to settings app. Opens settings page for this app.
*
* @param {Function} successCallback - The callback which will be called when switch to settings is successful.
* @param {Function} errorCallback - The callback which will be called when switch to settings encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.switchToSettings = function(successCallback, errorCallback) {
return cordova.exec(successCallback,
errorCallback,
'Diagnostic',
'switchToSettings',
[]);
};
/**
* Returns CPU architecture of the current device.
*
* @param {Function} successCallback - The callback which will be called when the operation is successful.
* This callback function is passed a single string parameter defined as a constant in `cordova.plugins.diagnostic.cpuArchitecture`.
* @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.getArchitecture = function(successCallback, errorCallback) {
return cordova.exec(successCallback,
errorCallback,
'Diagnostic',
'getArchitecture',
[]);
};
/**
* Returns the background refresh authorization status for the application.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single string parameter which indicates the authorization status as a constant in `cordova.plugins.diagnostic.permissionStatus`.
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.getBackgroundRefreshStatus = function(successCallback, errorCallback) {
return cordova.exec(successCallback,
errorCallback,
'Diagnostic',
'getBackgroundRefreshStatus',
[]);
};
/**
* Checks if the application is authorized for background refresh.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single boolean parameter which is TRUE if background refresh is authorized for use.
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.isBackgroundRefreshAuthorized = function(successCallback, errorCallback) {
Diagnostic.getBackgroundRefreshStatus(function(status){
successCallback(status === Diagnostic.permissionStatus.GRANTED);
}, errorCallback);
};
/**
* Returns the current battery level of the device as a percentage.
*
* @param {Function} successCallback - The callback which will be called when the operation is successful.
* This callback function is passed a single integer parameter which the current battery level percentage.
* @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.getCurrentBatteryLevel = function(successCallback, errorCallback){
return cordova.exec(successCallback,
errorCallback,
'Diagnostic',
'getCurrentBatteryLevel',
[]);
};
/**
* Checks if mobile data is authorized for this app.
* Returns true if the per-app Mobile Data setting is set to enabled (regardless of whether the device is currently connected to a cellular network)
*
* @param {Function} successCallback - The callback which will be called when the operation is successful.
* This callback function is passed a single boolean parameter which is TRUE if mobile data is enabled.
* @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.isMobileDataAuthorized = function(successCallback, errorCallback) {
return cordova.exec(Diagnostic._ensureBoolean(successCallback),
errorCallback,
'Diagnostic',
'isMobileDataAuthorized',
[]);
};
/**
* Checks if accessibility mode (VoiceOver) is enabled/running on device.
*
* @param {Function} successCallback - The callback which will be called when the operation is successful.
* This callback function is passed a single boolean parameter which is TRUE if accessibility mode is enabled.
* @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.isAccessibilityModeEnabled = function(successCallback, errorCallback) {
return cordova.exec(Diagnostic._ensureBoolean(successCallback),
errorCallback,
'Diagnostic',
'isAccessibilityModeEnabled',
[]);
};
/**
* Returns details of the OS of the device on which the app is currently running
*
* @param {Function} successCallback - The callback which will be called when the operation is successful.
* This callback function is passed a single object parameter with the following fields:
* - {string} version - version string of the OS e.g. "11.0"
* - {integer} apiLevel - API level of the OS e.g. 30
* - {string} apiName - code name for API level e.g. "FROYO"
* @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.getDeviceOSVersion = function(successCallback, errorCallback) {
return cordova.exec(successCallback,
errorCallback,
'Diagnostic',
'getDeviceOSVersion',
[]);
};
/**
* Returns details of the SDK levels used to build the app.
*
* @param {Function} successCallback - The callback which will be called when the operation is successful.
* This callback function is passed a single object parameter with the following fields:
* - {integer} targetApiLevel - API level of the target SDK (used to build the app)
* - {string} targetApiName - code name for API level of the target SDK e.g. "FROYO"
* - {integer} minApiLevel - API level of the minimum SDK (lowest on which the app can be installed)
* - {string} minApiName - code name for API level of the minimum SDK e.g. "FROYO"
* @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.getBuildOSVersion = function(successCallback, errorCallback) {
return cordova.exec(successCallback,
errorCallback,
'Diagnostic',
'getBuildOSVersion',
[]);
};
/**
* Checks if the current app build is a debug build.
*
* @param {Function} successCallback - The callback which will be called when the operation is successful.
* This callback function is passed a single boolean parameter which is TRUE if the app is a debug build.
* @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.isDebugBuild = function(successCallback, errorCallback) {
return cordova.exec(Diagnostic._ensureBoolean(successCallback),
errorCallback,
'Diagnostic',
'isDebugBuild',
[]);
};
/************
* Location *
************/
/**
* Checks if location is available for use by the app.
* On iOS this returns true if both the device setting for Location Services is ON AND the application is authorized to use location.
* When location is enabled, the locations returned are by a mixture GPS hardware, network triangulation and Wifi network IDs.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single boolean parameter which is TRUE if location is available for use.
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.isLocationAvailable = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.location){
cordova.plugins.diagnostic.location.isLocationAvailable.apply(this, arguments);
}else{
throw "Diagnostic Location module is not installed";
}
};
/**
* Checks if the device location setting is enabled.
* Returns true if Location Services is enabled.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single boolean parameter which is TRUE if Location Services is enabled.
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.isLocationEnabled = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.location){
cordova.plugins.diagnostic.location.isLocationEnabled.apply(this, arguments);
}else{
throw "Diagnostic Location module is not installed";
}
};
/**
* Checks if the application is authorized to use location.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single boolean parameter which is TRUE if application is authorized to use location either "when in use" (only in foreground) OR "always" (foreground and background).
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.isLocationAuthorized = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.location){
cordova.plugins.diagnostic.location.isLocationAuthorized.apply(this, arguments);
}else{
throw "Diagnostic Location module is not installed";
}
};
/**
* Returns the location authorization status for the application.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single string parameter which indicates the location authorization status as a constant in `cordova.plugins.diagnostic.permissionStatus`.
* Possible values are:
* `cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED`
* `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS`
* `cordova.plugins.diagnostic.permissionStatus.GRANTED`
* `cordova.plugins.diagnostic.permissionStatus.GRANTED_WHEN_IN_USE`
* Note that `GRANTED` indicates the app is always granted permission (even when in background).
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.getLocationAuthorizationStatus = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.location){
cordova.plugins.diagnostic.location.getLocationAuthorizationStatus.apply(this, arguments);
}else{
throw "Diagnostic Location module is not installed";
}
};
/**
* Returns the location accuracy authorization for the application.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single string parameter which indicates the location accuracy authorization as a constant in `cordova.plugins.diagnostic.locationAccuracyAuthorization`.
* Possible values are:
* `cordova.plugins.diagnostic.locationAccuracyAuthorization.FULL`
* `cordova.plugins.diagnostic.locationAccuracyAuthorization.REDUCED`
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.getLocationAccuracyAuthorization = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.location){
cordova.plugins.diagnostic.location.getLocationAccuracyAuthorization.apply(this, arguments);
}else{
throw "Diagnostic Location module is not installed";
}
};
/**
* Requests location authorization for the application.
* Authorization can be requested to use location either "when in use" (only in foreground) or "always" (foreground and background).
* Should only be called if authorization status is NOT_REQUESTED. Calling it when in any other state will have no effect.
*
* @param {Function} successCallback - Invoked in response to the user's choice in the permission dialog.
* It is passed a single string parameter which defines the resulting authorisation status as a constant in `cordova.plugins.diagnostic.permissionStatus`.
* Possible values are:
* `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS`
* `cordova.plugins.diagnostic.permissionStatus.GRANTED`
* `cordova.plugins.diagnostic.permissionStatus.GRANTED_WHEN_IN_USE`
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
* @param {String} mode - (optional) location authorization mode as a constant in `cordova.plugins.diagnostic.locationAuthorizationMode`.
* If not specified, defaults to `cordova.plugins.diagnostic.locationAuthorizationMode.WHEN_IN_USE`.
*/
Diagnostic.requestLocationAuthorization = function(successCallback, errorCallback, mode) {
if(cordova.plugins.diagnostic.location){
cordova.plugins.diagnostic.location.requestLocationAuthorization.apply(this, arguments);
}else{
throw "Diagnostic Location module is not installed";
}
};
/**
* Requests temporary access to full location accuracy for the application.
* By default on iOS 14+, when a user grants location permission, the app can only receive reduced accuracy locations.
* If your app requires full (high-accuracy GPS) locations (e.g. a SatNav app), you need to call this method.
* Should only be called if location authorization has been granted.
*
* @param {String} purpose - (required) corresponds to a key in the NSLocationTemporaryUsageDescriptionDictionary entry in your app's `*-Info.plist`
* which contains a message explaining the user why your app needs their exact location.
* This will be presented to the user via permission dialog in which they can either accept or reject the request.
* @param {Function} successCallback - (optional) Invoked in response to the user's choice in the permission dialog.
* It is passed a single string parameter which defines the resulting accuracy authorization as a constant in `cordova.plugins.diagnostic.locationAccuracyAuthorization`.
* Possible values are:
* `cordova.plugins.diagnostic.locationAccuracyAuthorization.FULL`
* `cordova.plugins.diagnostic.locationAccuracyAuthorization.REDUCED`
* @param {Function} errorCallback - (optional) The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.requestTemporaryFullAccuracyAuthorization = function(purpose, successCallback, errorCallback) {
if(cordova.plugins.diagnostic.location){
cordova.plugins.diagnostic.location.requestTemporaryFullAccuracyAuthorization.apply(this, arguments);
}else{
throw "Diagnostic Location module is not installed";
}
};
/**
* Registers a function to be called when a change in Location state occurs.
* On iOS, this occurs when location authorization status is changed.
* This can be triggered either by the user's response to a location permission authorization dialog,
* by the user turning on/off Location Services,
* or by the user changing the Location authorization state specifically for your app.
* Pass in a falsey value to de-register the currently registered function.
*
* @param {Function} successCallback - The callback which will be called when the Location state changes.
* This callback function is passed a single string parameter indicating the new location authorisation status as a constant in `cordova.plugins.diagnostic.permissionStatus`.
*/
Diagnostic.registerLocationStateChangeHandler = function(successCallback) {
if(cordova.plugins.diagnostic.location){
cordova.plugins.diagnostic.location.registerLocationStateChangeHandler.apply(this, arguments);
}else{
throw "Diagnostic Location module is not installed";
}
};
/**
* Registers a function to be called when a change in location accuracy authorization occurs.
* This occurs when location accuracy authorization is changed.
* This can be triggered either by the user's response to a location accuracy authorization dialog,
* or by the user changing the location accuracy authorization specifically for your app in Settings.
* Pass in a falsey value to de-register the currently registered function.
*
* @param {Function} successCallback - The callback which will be called when the location accuracy authorization changes.
* This callback function is passed a single string parameter indicating the new location accuracy authorization as a constant in `cordova.plugins.diagnostic.locationAccuracyAuthorization`.
*/
Diagnostic.registerLocationAccuracyAuthorizationChangeHandler = function(successCallback) {
if(cordova.plugins.diagnostic.location){
cordova.plugins.diagnostic.location.registerLocationAccuracyAuthorizationChangeHandler.apply(this, arguments);
}else{
throw "Diagnostic Location module is not installed";
}
};
/************
* Camera *
************/
/**
* Checks if camera is enabled for use.
* On iOS this returns true if both the device has a camera AND the application is authorized to use it.
*
* @param {Object} params - (optional) parameters:
* - {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single boolean parameter which is TRUE if camera is present and authorized for use.
* - {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.isCameraAvailable = function(params) {
if(cordova.plugins.diagnostic.camera){
cordova.plugins.diagnostic.camera.isCameraAvailable.apply(this, arguments);
}else{
throw "Diagnostic Camera module is not installed";
}
};
/**
* Checks if camera hardware is present on device.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single boolean parameter which is TRUE if camera is present
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.isCameraPresent = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.camera){
cordova.plugins.diagnostic.camera.isCameraPresent.apply(this, arguments);
}else{
throw "Diagnostic Camera module is not installed";
}
};
/**
* Checks if the application is authorized to use the camera.
*
* @param {Object} params - (optional) parameters:
* - {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single boolean parameter which is TRUE if camera is authorized for use.
* - {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.isCameraAuthorized = function(params) {
if(cordova.plugins.diagnostic.camera){
cordova.plugins.diagnostic.camera.isCameraAuthorized.apply(this, arguments);
}else{
throw "Diagnostic Camera module is not installed";
}
};
/**
* Returns the camera authorization status for the application.
*
* @param {Object} params - (optional) parameters:
* - {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single string parameter which indicates the authorization status as a constant in `cordova.plugins.diagnostic.permissionStatus`.
* - {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.getCameraAuthorizationStatus = function(params) {
if(cordova.plugins.diagnostic.camera){
cordova.plugins.diagnostic.camera.getCameraAuthorizationStatus.apply(this, arguments);
}else{
throw "Diagnostic Camera module is not installed";
}
};
/**
* Requests camera authorization for the application.
* Should only be called if authorization status is NOT_REQUESTED. Calling it when in any other state will have no effect.
*
* @param {Object} params - (optional) parameters:
* - {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single string parameter indicating whether access to the camera was granted or denied:
* `cordova.plugins.diagnostic.permissionStatus.GRANTED` or `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS`
* - {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.requestCameraAuthorization = function(params){
if(cordova.plugins.diagnostic.camera){
cordova.plugins.diagnostic.camera.requestCameraAuthorization.apply(this, arguments);
}else{
throw "Diagnostic Camera module is not installed";
}
};
/**
* Checks if the application is authorized to use the Camera Roll in Photos app.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single boolean parameter which is TRUE if access to Camera Roll is authorized.
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
* @param {Function} accessLevel - (optional) On iOS 14+, specifies the level of access to the photo library to query as a constant in cordova.plugins.diagnostic.photoLibraryAccessLevel`
* - Possible values are:
* - ADD_ONLY - can add to but not read from Photo Library
* - READ_WRITE - can both add to and read from Photo Library
* - Defaults to ADD_ONLY if not specified
* - Has no effect on iOS 13 or below
*/
Diagnostic.isCameraRollAuthorized = function(successCallback, errorCallback, accessLevel) {
if(cordova.plugins.diagnostic.camera){
cordova.plugins.diagnostic.camera.isCameraRollAuthorized.apply(this, arguments);
}else{
throw "Diagnostic Camera module is not installed";
}
};
/**
* Returns the authorization status for the application to use the Camera Roll in Photos app.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single string parameter which indicates the authorization status as a constant in `cordova.plugins.diagnostic.permissionStatus`.
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
* @param {Function} accessLevel - (optional) On iOS 14+, specifies the level of access to the photo library to query as a constant in cordova.plugins.diagnostic.photoLibraryAccessLevel`
* - Possible values are:
* - ADD_ONLY - can add to but not read from Photo Library
* - READ_WRITE - can both add to and read from Photo Library
* - Defaults to ADD_ONLY if not specified
* - Has no effect on iOS 13 or below
*/
Diagnostic.getCameraRollAuthorizationStatus = function(successCallback, errorCallback, accessLevel) {
if(cordova.plugins.diagnostic.camera){
cordova.plugins.diagnostic.camera.getCameraRollAuthorizationStatus.apply(this, arguments);
}else{
throw "Diagnostic Camera module is not installed";
}
};
/**
* Requests camera roll authorization for the application.
* Should only be called if authorization status is NOT_REQUESTED. Calling it when in any other state will have no effect.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single string parameter indicating the new authorization status:
* `cordova.plugins.diagnostic.permissionStatus.GRANTED` or `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS`
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
* @param {Function} accessLevel - On iOS 14+, specifies the level of access to the photo library as a constant in cordova.plugins.diagnostic.photoLibraryAccessLevel`
* - Possible values are:
* - ADD_ONLY - can add to but not read from Photo Library
* - READ_WRITE - can both add to and read from Photo Library
* - Defaults to ADD_ONLY if not specified
* - Has no effect on iOS 13 or below
*/
Diagnostic.requestCameraRollAuthorization = function(successCallback, errorCallback, accessLevel) {
if(cordova.plugins.diagnostic.camera){
cordova.plugins.diagnostic.camera.requestCameraRollAuthorization.apply(this, arguments);
}else{
throw "Diagnostic Camera module is not installed";
}
};
Diagnostic.presentLimitedLibraryPicker = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.camera){
cordova.plugins.diagnostic.camera.presentLimitedLibraryPicker.apply(this, arguments);
}else{
throw "Diagnostic Camera module is not installed";
}
};
/************
* WiFi *
************/
/**
* Checks if Wi-Fi is connected.
* On iOS this returns true if the WiFi setting is set to enabled AND the device is connected to a network by WiFi.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single boolean parameter which is TRUE if device is connected by WiFi.
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.isWifiAvailable = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.wifi){
cordova.plugins.diagnostic.wifi.isWifiAvailable.apply(this, arguments);
}else{
throw "Diagnostic Wifi module is not installed";
}
};
/**
* Checks if Wifi is enabled.
* On iOS this returns true if the WiFi setting is set to enabled (regardless of whether it's connected to a network).
*
* @param {Function} successCallback - The callback which will be called when the operation is successful.
* This callback function is passed a single boolean parameter which is TRUE if WiFi is enabled.
* @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.isWifiEnabled = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.wifi){
cordova.plugins.diagnostic.wifi.isWifiEnabled.apply(this, arguments);
}else{
throw "Diagnostic Wifi module is not installed";
}
};
/***************
* Bluetooth *
***************/
/**
* Checks if the device has Bluetooth LE capabilities and if so that Bluetooth is switched on
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single boolean parameter which is TRUE if device has Bluetooth LE and Bluetooth is switched on.
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.isBluetoothAvailable = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.bluetooth){
cordova.plugins.diagnostic.bluetooth.isBluetoothAvailable.apply(this, arguments);
}else{
throw "Diagnostic Bluetooth module is not installed";
}
};
/**
* Returns the state of Bluetooth LE on the device.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single string parameter which indicates the Bluetooth state as a constant in `cordova.plugins.diagnostic.bluetoothState`.
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.getBluetoothState = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.bluetooth){
cordova.plugins.diagnostic.bluetooth.getBluetoothState.apply(this, arguments);
}else{
throw "Diagnostic Bluetooth module is not installed";
}
};
/**
* Registers a function to be called when a change in Bluetooth state occurs.
* Pass in a falsey value to de-register the currently registered function.
*
* @param {Function} successCallback - function call when a change in Bluetooth state occurs.
* This callback function is passed a single string parameter which indicates the Bluetooth state as a constant in `cordova.plugins.diagnostic.bluetoothState`.
*/
Diagnostic.registerBluetoothStateChangeHandler = function(successCallback){
if(cordova.plugins.diagnostic.bluetooth){
cordova.plugins.diagnostic.bluetooth.registerBluetoothStateChangeHandler.apply(this, arguments);
}else{
throw "Diagnostic Bluetooth module is not installed";
}
};
/**
* Requests Bluetooth authorization for the application.
* The outcome of the authorization request can be determined by registering a handler using `registerBluetoothStateChangeHandler()`.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is not passed any parameters.
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.requestBluetoothAuthorization = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.bluetooth){
cordova.plugins.diagnostic.bluetooth.requestBluetoothAuthorization.apply(this, arguments);
}else{
throw "Diagnostic Bluetooth module is not installed";
}
};
Diagnostic.getBluetoothAuthorizationStatus = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.bluetooth){
cordova.plugins.diagnostic.bluetooth.getAuthorizationStatus.apply(this, arguments);
}else{
throw "Diagnostic Bluetooth module is not installed";
}
};
/***********************
* Remote Notifications
***********************/
/**
* Checks if remote (push) notifications are enabled.
* Returns true if app is registered for remote notifications AND "Allow Notifications" switch is ON AND alert style is not set to "None" (i.e. "Banners" or "Alerts").
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single boolean parameter which is TRUE if remote (push) notifications are enabled.
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.isRemoteNotificationsEnabled = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.notifications){
cordova.plugins.diagnostic.notifications.isRemoteNotificationsEnabled.apply(this, arguments);
}else{
throw "Diagnostic Notifications module is not installed";
}
};
/**
* Switches to the notification settings page in the Settings app
*
* @param {Function} successCallback - The callback which will be called when switch to settings is successful.
* @param {Function} errorCallback - The callback which will be called when switch to settings encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.switchToNotificationSettings = function(successCallback, errorCallback) {
if (cordova.plugins.diagnostic.notifications){
cordova.plugins.diagnostic.notifications.switchToNotificationSettings.apply(this, arguments);
} else {
throw "Diagnostic Notification module is not installed";
}
};
/**
* Indicates the current setting of notification types for the app in the Settings app.
* Note: if "Allow Notifications" switch is OFF, all types will be returned as disabled.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single object parameter where the key is the notification type as a constant in `cordova.plugins.diagnostic.remoteNotificationType` and the value is a boolean indicating whether it's enabled:
* cordova.plugins.diagnostic.remoteNotificationType.ALERT => alert style is not set to "None" (i.e. "Banners" or "Alerts").
* cordova.plugins.diagnostic.remoteNotificationType.BADGE => "Badge App Icon" switch is ON.
* cordova.plugins.diagnostic.remoteNotificationType.SOUND => "Sounds"/"Alert Sound" switch is ON.
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.getRemoteNotificationTypes = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.notifications){
cordova.plugins.diagnostic.notifications.getRemoteNotificationTypes.apply(this, arguments);
}else{
throw "Diagnostic Notifications module is not installed";
}
};
/**
* Indicates if the app is registered for remote notifications on the device.
* Returns true if the app is registered for remote notifications and received its device token,
* or false if registration has not occurred, has failed, or has been denied by the user.
* Note that user preferences for notifications in the Settings app will not affect this.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single boolean parameter which is TRUE if the device is registered for remote (push) notifications.
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.isRegisteredForRemoteNotifications = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.notifications){
cordova.plugins.diagnostic.notifications.isRegisteredForRemoteNotifications.apply(this, arguments);
}else{
throw "Diagnostic Notifications module is not installed";
}
};
/**
* Returns the remote notifications authorization status for the application.
*
* @param {Object} params - (optional) parameters:
* - {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single string parameter which indicates the authorization status as a constant in `cordova.plugins.diagnostic.permissionStatus`.
* Possible values are:
* `cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED`
* `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS`
* `cordova.plugins.diagnostic.permissionStatus.GRANTED`
* - {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.getRemoteNotificationsAuthorizationStatus = function() {
if(cordova.plugins.diagnostic.notifications){
cordova.plugins.diagnostic.notifications.getRemoteNotificationsAuthorizationStatus.apply(this, arguments);
}else{
throw "Diagnostic Notifications module is not installed";
}
};
/**
* Requests remote notifications authorization for the application.
*
* @param {Object} params - (optional) parameters:
* - {Function} successCallback - The callback which will be called when operation is successful.
* - {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
* @param {Array} types - list of notifications to register for as constants in `cordova.plugins.diagnostic.remoteNotificationType`.
* If not specified, defaults to all notification types.
* @param {Boolean} omitRegistration - If true, registration for remote notifications will not be carried out once remote notifications authorization is granted.
* Defaults to false (registration will automatically take place once authorization is granted).
*/
Diagnostic.requestRemoteNotificationsAuthorization = function() {
if(cordova.plugins.diagnostic.notifications){
cordova.plugins.diagnostic.notifications.requestRemoteNotificationsAuthorization.apply(this, arguments);
}else{
throw "Diagnostic Notifications module is not installed";
}
};
/***************************
* Microphone / Record Audio
***************************/
/**
* Checks if the application is authorized to use the microphone for recording audio.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single boolean parameter which is TRUE if access to microphone is authorized.
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.isMicrophoneAuthorized = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.microphone){
cordova.plugins.diagnostic.microphone.isMicrophoneAuthorized.apply(this, arguments);
}else{
throw "Diagnostic Microphone module is not installed";
}
};
/**
* Returns the authorization status for the application to use the microphone for recording audio.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single string parameter which indicates the authorization status as a constant in `cordova.plugins.diagnostic.permissionStatus`.
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.getMicrophoneAuthorizationStatus = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.microphone){
cordova.plugins.diagnostic.microphone.getMicrophoneAuthorizationStatus.apply(this, arguments);
}else{
throw "Diagnostic Microphone module is not installed";
}
};
/**
* Requests access to microphone if authorization was never granted nor denied, will only return access status otherwise.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single string parameter indicating whether access to the microphone was granted or denied:
* `cordova.plugins.diagnostic.permissionStatus.GRANTED` or `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS`
* @param {Function} errorCallback - The callback which will be called when an error occurs.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.requestMicrophoneAuthorization = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.microphone){
cordova.plugins.diagnostic.microphone.requestMicrophoneAuthorization.apply(this, arguments);
}else{
throw "Diagnostic Microphone module is not installed";
}
};
/*************
* Contacts
*************/
/**
* Checks if the application is authorized to use contacts (address book).
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single boolean parameter which is TRUE if contacts is authorized for use.
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.isContactsAuthorized = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.contacts){
cordova.plugins.diagnostic.contacts.isContactsAuthorized.apply(this, arguments);
}else{
throw "Diagnostic Contacts module is not installed";
}
};
/**
* Returns the contacts (address book) authorization status for the application.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single string parameter which indicates the authorization status as a constant in `cordova.plugins.diagnostic.permissionStatus`.
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.getContactsAuthorizationStatus = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.contacts){
cordova.plugins.diagnostic.contacts.getContactsAuthorizationStatus.apply(this, arguments);
}else{
throw "Diagnostic Contacts module is not installed";
}
};
/**
* Requests contacts (address book) authorization for the application.
* Should only be called if authorization status is NOT_REQUESTED. Calling it when in any other state will have no effect.
*
* @param {Function} successCallback - The callback which will be called when operation is successful.
* This callback function is passed a single string parameter indicating whether access to contacts was granted or denied:
* `cordova.plugins.diagnostic.permissionStatus.GRANTED` or `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS`
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
* This callback function is passed a single string parameter containing the error message.
*/
Diagnostic.requestContactsAuthorization = function(successCallback, errorCallback) {
if(cordova.plugins.diagnostic.contacts){
cordova.plugins.diagnostic.contacts.requestContactsAuthorization.apply(th