├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── documentation-issue.md │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md └── stale.yml ├── .gitignore ├── CHANGELOG.md ├── README.md ├── cordova.plugins.diagnostic.d.ts ├── package.json ├── plugin.xml ├── scripts ├── apply-modules.js └── logger.js ├── src ├── android │ ├── Diagnostic.java │ ├── Diagnostic_Bluetooth.java │ ├── Diagnostic_Camera.java │ ├── Diagnostic_External_Storage.java │ ├── Diagnostic_Location.java │ ├── Diagnostic_NFC.java │ ├── Diagnostic_Notifications.java │ └── Diagnostic_Wifi.java └── ios │ ├── Diagnostic.h │ ├── Diagnostic.m │ ├── Diagnostic_Bluetooth.h │ ├── Diagnostic_Bluetooth.m │ ├── Diagnostic_Calendar.h │ ├── Diagnostic_Calendar.m │ ├── Diagnostic_Camera.h │ ├── Diagnostic_Camera.m │ ├── Diagnostic_Contacts.h │ ├── Diagnostic_Contacts.m │ ├── Diagnostic_Location.h │ ├── Diagnostic_Location.m │ ├── Diagnostic_Microphone.h │ ├── Diagnostic_Microphone.m │ ├── Diagnostic_Motion.h │ ├── Diagnostic_Motion.m │ ├── Diagnostic_Notifications.h │ ├── Diagnostic_Notifications.m │ ├── Diagnostic_Reminders.h │ ├── Diagnostic_Reminders.m │ ├── Diagnostic_Resources.bundle │ └── PrivacyInfo.xcprivacy │ ├── Diagnostic_Wifi.h │ └── Diagnostic_Wifi.m └── www ├── android ├── diagnostic.bluetooth.js ├── diagnostic.calendar.js ├── diagnostic.camera.js ├── diagnostic.contacts.js ├── diagnostic.external_storage.js ├── diagnostic.js ├── diagnostic.location.js ├── diagnostic.microphone.js ├── diagnostic.nfc.js ├── diagnostic.notifications.js └── diagnostic.wifi.js └── ios ├── diagnostic.bluetooth.js ├── diagnostic.calendar.js ├── diagnostic.camera.js ├── diagnostic.contacts.js ├── diagnostic.js ├── diagnostic.location.js ├── diagnostic.microphone.js ├── diagnostic.motion.js ├── diagnostic.notifications.js ├── diagnostic.reminders.js └── diagnostic.wifi.js /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [ dpa99c ] 4 | custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=ZRD3W47HQ3EMJ&source=url 5 | patreon: dpa99c 6 | ko_fi: davealden -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Report a problem 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 15 | 16 | 17 | 18 | # Bug report 19 | 20 | 21 | **CHECKLIST** 22 | - [ ] I have read the [issue reporting guidelines](https://github.com/dpa99c/cordova-diagnostic-plugin#reporting-issues) 23 | 24 | - [ ] I confirm this is a suspected bug or issue that will affect other users 25 | 26 | 27 | - [ ] I have reproduced the issue using the [example project](https://github.com/dpa99c/cordova-diagnostic-plugin-example) or provided the necessary information to reproduce the issue. 28 | 29 | 30 | - [ ] I have read [the documentation](https://github.com/dpa99c/cordova-diagnostic-plugin) thoroughly and it does not help solve my issue. 31 | 32 | 33 | - [ ] I have checked that no similar issues (open or closed) already exist. 34 | 35 | 36 | **Current behavior:** 37 | 38 | 39 | 40 | 44 | 45 | **Expected behavior:** 46 | 47 | 48 | **Steps to reproduce:** 49 | 50 | 51 | **Screenshots** 52 | 53 | 54 | **Environment information** 55 | 56 | - Cordova CLI version 57 | - `cordova -v` 58 | - Cordova platform version 59 | - `cordova platform ls` 60 | - Plugins & versions installed in project (including this plugin) 61 | - `cordova plugin ls` 62 | - Dev machine OS and version, e.g. 63 | - OSX 64 | - `sw_vers` 65 | 66 | _Runtime issue_ 67 | - Device details 68 | - _e.g. iPhone X, Samsung Galaxy S8, iPhone X Simulator, Pixel XL Emulator_ 69 | - OS details 70 | - _e.g. iOS 12.2, Android 9.0_ 71 | 72 | _Android build issue:_ 73 | - Node JS version 74 | - `node -v` 75 | - Gradle version 76 | - `ls platforms/android/.gradle` 77 | - Target Android SDK version 78 | - `android:targetSdkVersion` in `AndroidManifest.xml` 79 | - Android SDK details 80 | - `sdkmanager --list | sed -e '/Available Packages/q'` 81 | 82 | _iOS build issue:_ 83 | - Node JS version 84 | - `node -v` 85 | - XCode version 86 | 87 | 88 | **Related code:** 89 | ``` 90 | insert any relevant code here such as plugin API calls / input parameters 91 | ``` 92 | 93 | **Console output** 94 |
95 | console output 96 | 97 | ``` 98 | 99 | // Paste any relevant JS/native console output here 100 | 101 | ``` 102 | 103 |


104 | 105 | **Other information:** 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 122 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation-issue.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Documentation issue 3 | about: Describe an issue with the documentation 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 16 | 17 | 18 | # Documentation issue 19 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 15 | 16 | 17 | # Feature request 18 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## PR Type 2 | What kind of change does this PR introduce? 3 | 4 | 5 | - [ ] Bugfix 6 | - [ ] Feature 7 | - [ ] Code style update (formatting, local variables) 8 | - [ ] Refactoring (no functional changes, no api changes) 9 | - [ ] Documentation changes 10 | - [ ] Other... Please describe: 11 | 12 | 13 | 14 | ## PR Checklist 15 | For bug fixes / features, please check if your PR fulfills the following requirements: 16 | 17 | - [ ] Testing has been carried out for the changes have been added 18 | - [ ] Regression testing has been carried out for existing functionality 19 | - [ ] Docs have been added / updated 20 | 21 | ## What is the purpose of this PR? 22 | 23 | 24 | 25 | ## Does this PR introduce a breaking change? 26 | - [ ] Yes 27 | - [ ] No 28 | 29 | 30 | 31 | ## What testing has been done on the changes in the PR? 32 | 33 | 34 | ## What testing has been done on existing functionality? 35 | 36 | 37 | ## Other information -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 60 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 7 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - pinned 8 | - security 9 | # Label to use when marking an issue as stale 10 | staleLabel: wontfix 11 | # Comment to post when marking an issue as stale. Set to `false` to disable 12 | markComment: > 13 | This issue has been automatically marked as stale because it has not had 14 | recent activity. It will be closed if no further activity occurs. Thank you 15 | for your contributions. 16 | # Comment to post when closing a stale issue. Set to `false` to disable 17 | closeComment: false -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | node_modules 3 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "7.2.3", 3 | "name": "cordova.plugins.diagnostic", 4 | "cordova_name": "Diagnostic", 5 | "description": "Cordova/Phonegap plugin to check the state of Location/WiFi/Camera/Bluetooth device settings.", 6 | "author": "Dave Alden", 7 | "license": "MIT", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/dpa99c/cordova-diagnostic-plugin.git" 11 | }, 12 | "issue": "https://github.com/dpa99c/cordova-diagnostic-plugin/issues", 13 | "cordova": { 14 | "id": "cordova.plugins.diagnostic", 15 | "platforms": [ 16 | "android", 17 | "ios" 18 | ] 19 | }, 20 | "keywords": [ 21 | "ecosystem:cordova", 22 | "cordova", 23 | "android", 24 | "ios", 25 | "phonegap", 26 | "diagnostic", 27 | "wifi", 28 | "location", 29 | "gps", 30 | "camera", 31 | "bluetooth", 32 | "settings" 33 | ], 34 | "types": "./cordova.plugins.diagnostic.d.ts", 35 | "dependencies": { 36 | "colors": "1.4.0", 37 | "elementtree": "^0.1.6", 38 | "minimist": "1.2.6" 39 | }, 40 | "scripts": { 41 | "postinstall": "node ./scripts/apply-modules.js" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /scripts/apply-modules.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /********** 4 | * Globals 5 | **********/ 6 | 7 | const PLUGIN_NAME = "Diagnostic plugin"; 8 | const PLUGIN_ID = "cordova.plugins.diagnostic"; 9 | const PREFERENCE_NAME = PLUGIN_ID + ".modules"; 10 | 11 | const MODULES = [ 12 | "LOCATION", 13 | "BLUETOOTH", 14 | "WIFI", 15 | "CAMERA", 16 | "NOTIFICATIONS", 17 | "MICROPHONE", 18 | "CONTACTS", 19 | "CALENDAR", 20 | "REMINDERS", 21 | "MOTION", 22 | "NFC", 23 | "EXTERNAL_STORAGE", 24 | "AIRPLANE_MODE" 25 | ]; 26 | 27 | const COMMENT_START = ""; 29 | 30 | // Node dependencies 31 | var path, cwd, fs; 32 | 33 | // External dependencies 34 | var et; 35 | 36 | // Internal dependencies 37 | var logger; 38 | 39 | var projectPath, modulesPath, pluginNodePath, pluginScriptsPath, configXmlPath, pluginXmlPath, configXmlData, pluginXmlText; 40 | 41 | 42 | /********************* 43 | * Internal functions 44 | *********************/ 45 | 46 | var run = function (){ 47 | var configuredModules = getSelectedModules(); 48 | logger.verbose("Modules: " + configuredModules); 49 | 50 | readPluginXml(); 51 | enableAllModules(); 52 | if(configuredModules){ 53 | MODULES.forEach(function(module){ 54 | if(configuredModules.indexOf(module) === -1){ 55 | disableModule(module); 56 | } 57 | }); 58 | } 59 | 60 | writePluginXml(); 61 | }; 62 | 63 | 64 | var handleError = function (error) { 65 | error = PLUGIN_NAME + " - ERROR: " + error; 66 | if(logger){ 67 | logger.error(error); 68 | }else{ 69 | console.log(error); 70 | console.error(error) 71 | } 72 | return error; 73 | }; 74 | 75 | // Parses a given file into an elementtree object 76 | var parseElementtreeSync = function(filename) { 77 | var contents = fs.readFileSync(filename, 'utf-8'); 78 | if(contents) { 79 | //Windows is the BOM. Skip the Byte Order Mark. 80 | contents = contents.substring(contents.indexOf('<')); 81 | } 82 | return new et.ElementTree(et.XML(contents)); 83 | }; 84 | 85 | // Parses the config.xml into an elementtree object and stores in the config object 86 | var getConfigXml = function() { 87 | if(!configXmlData) { 88 | configXmlData = parseElementtreeSync(configXmlPath); 89 | } 90 | return configXmlData; 91 | }; 92 | 93 | var readPluginXml = function(){ 94 | pluginXmlText = fs.readFileSync(pluginXmlPath, 'utf-8'); 95 | }; 96 | 97 | var writePluginXml = function(){ 98 | fs.writeFileSync(pluginXmlPath, pluginXmlText, 'utf-8'); 99 | }; 100 | 101 | var getSelectedModules = function(){ 102 | var modules = null; 103 | var preference = getConfigXml().findall("preference[@name='"+PREFERENCE_NAME+"']")[0]; 104 | if(preference){ 105 | modules = preference.attrib.value.split(' '); 106 | } 107 | return modules; 108 | }; 109 | 110 | var enableAllModules = function(){ 111 | MODULES.forEach(function(module){ 112 | var commentedStartRegExp = new RegExp(getModuleStart(module)+COMMENT_START, "g"); 113 | var commentedEndRegExp = new RegExp(COMMENT_END+getModuleEnd(module), "g"); 114 | if(pluginXmlText.match(commentedStartRegExp)){ 115 | pluginXmlText = pluginXmlText.replace(commentedStartRegExp, getModuleStart(module)); 116 | pluginXmlText = pluginXmlText.replace(commentedEndRegExp, getModuleEnd(module)); 117 | } 118 | }); 119 | }; 120 | 121 | var disableModule = function(module){ 122 | var commentedStart = getModuleStart(module)+COMMENT_START; 123 | var commentedEnd = COMMENT_END+getModuleEnd(module); 124 | pluginXmlText = pluginXmlText.replace(new RegExp(getModuleStart(module), "g"), commentedStart); 125 | pluginXmlText = pluginXmlText.replace(new RegExp(getModuleEnd(module), "g"), commentedEnd); 126 | }; 127 | 128 | var getModuleStart = function(module){ 129 | return ""; 130 | }; 131 | 132 | var getModuleEnd = function(module){ 133 | return ""; 134 | }; 135 | 136 | 137 | /********** 138 | * Main 139 | **********/ 140 | var main = function() { 141 | try{ 142 | fs = require('fs'); 143 | path = require('path'); 144 | cwd = path.resolve(); 145 | pluginNodePath = cwd; 146 | 147 | modulesPath = path.resolve(pluginNodePath, ".."); 148 | projectPath = path.resolve(modulesPath, ".."); 149 | pluginScriptsPath = path.resolve(pluginNodePath, "scripts"); 150 | 151 | logger = require(path.resolve(pluginScriptsPath, "logger.js"))(modulesPath, PLUGIN_ID); 152 | et = require(path.resolve(modulesPath, "elementtree")); 153 | }catch(e){ 154 | handleError("Failed to load dependencies. If using cordova@6 CLI, ensure this plugin is installed with the --fetch option or run 'npm install "+PLUGIN_ID+"': " + e.message); 155 | } 156 | 157 | try{ 158 | configXmlPath = path.join(projectPath, 'config.xml'); 159 | pluginXmlPath = path.join(pluginNodePath, "plugin.xml"); 160 | run(); 161 | }catch(e){ 162 | handleError(e.message); 163 | } 164 | }; 165 | 166 | main(); -------------------------------------------------------------------------------- /scripts/logger.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var logger = (function(){ 4 | 5 | /********************** 6 | * Internal properties 7 | *********************/ 8 | var logger, path, minimist, 9 | modulesPath, pluginId, hasColors = true, cliArgs; 10 | 11 | function prefixMsg(msg){ 12 | return pluginId+": "+msg; 13 | } 14 | 15 | /************ 16 | * Public API 17 | ************/ 18 | logger = { 19 | init: function(_modulesPath, _pluginId){ 20 | pluginId = _pluginId; 21 | modulesPath = _modulesPath; 22 | 23 | path = require('path'); 24 | 25 | try{ 26 | require(path.resolve(modulesPath, "colors")); 27 | }catch(e){ 28 | hasColors = false; 29 | } 30 | 31 | minimist = require(path.resolve(modulesPath, "minimist")); 32 | cliArgs = minimist(process.argv.slice(2)); 33 | }, 34 | dump: function (obj){ 35 | if(cliArgs["--debug"] || cliArgs["--dump"]) { 36 | console.log("DUMP: "+require('util').inspect(obj)); 37 | } 38 | }, 39 | debug: function(msg){ 40 | if(cliArgs["--debug"]){ 41 | msg = "DEBUG: " + msg; 42 | console.log(msg); 43 | } 44 | }, 45 | verbose: function(msg){ 46 | if(cliArgs["--verbose"] || cliArgs["--debug"]){ 47 | msg = prefixMsg(msg); 48 | if(hasColors){ 49 | console.log(msg.green); 50 | }else{ 51 | console.log(msg); 52 | } 53 | } 54 | }, 55 | log: function(msg){ 56 | msg = prefixMsg(msg); 57 | if(hasColors){ 58 | console.log(msg.white); 59 | }else{ 60 | console.log(msg); 61 | } 62 | }, 63 | info: function(msg){ 64 | msg = prefixMsg(msg); 65 | if(hasColors){ 66 | console.log(msg.blue); 67 | }else{ 68 | console.info(msg); 69 | } 70 | }, 71 | warn: function(msg){ 72 | msg = prefixMsg(msg); 73 | if(hasColors){ 74 | console.log(msg.yellow); 75 | }else{ 76 | console.warn(msg); 77 | } 78 | }, 79 | error: function(msg){ 80 | msg = prefixMsg(msg); 81 | if(hasColors){ 82 | console.log(msg.red); 83 | }else{ 84 | console.error(msg); 85 | } 86 | } 87 | }; 88 | return logger; 89 | })(); 90 | 91 | module.exports = function(modulesPath, pluginId){ 92 | logger.init(modulesPath, pluginId); 93 | return logger; 94 | }; -------------------------------------------------------------------------------- /src/android/Diagnostic_Camera.java: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an 14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, either express or implied. See the License for the 16 | specific language governing permissions and limitations 17 | under the License. 18 | */ 19 | package cordova.plugins; 20 | 21 | /* 22 | * Imports 23 | */ 24 | 25 | import android.content.pm.PackageManager; 26 | import android.hardware.Camera; 27 | import android.util.Log; 28 | import android.os.Build; 29 | 30 | import org.apache.cordova.CallbackContext; 31 | import org.apache.cordova.CordovaInterface; 32 | import org.apache.cordova.CordovaPlugin; 33 | import org.apache.cordova.CordovaWebView; 34 | import org.json.JSONArray; 35 | import org.json.JSONException; 36 | import org.json.JSONObject; 37 | 38 | import java.util.Objects; 39 | 40 | /** 41 | * Diagnostic plugin implementation for Android 42 | */ 43 | public class Diagnostic_Camera extends CordovaPlugin{ 44 | 45 | 46 | /************* 47 | * Constants * 48 | *************/ 49 | 50 | 51 | /** 52 | * Tag for debug log messages 53 | */ 54 | public static final String TAG = "Diagnostic_Camera"; 55 | 56 | protected static final String cameraPermission = "CAMERA"; 57 | protected static String[] storagePermissions; 58 | static { 59 | if (android.os.Build.VERSION.SDK_INT >= 34) { // Build.VERSION_CODES.UPSIDE_DOWN_CAKE / Android 14 60 | storagePermissions = new String[]{ "READ_MEDIA_IMAGES", "READ_MEDIA_VIDEO", "READ_MEDIA_VISUAL_USER_SELECTED" }; 61 | } else if (android.os.Build.VERSION.SDK_INT >= 33) { // Build.VERSION_CODES.TIRAMISU / Android 13 62 | storagePermissions = new String[]{ "READ_MEDIA_IMAGES", "READ_MEDIA_VIDEO" }; 63 | } else { 64 | storagePermissions = new String[]{ "READ_EXTERNAL_STORAGE", "WRITE_EXTERNAL_STORAGE" }; 65 | } 66 | } 67 | 68 | 69 | /************* 70 | * Variables * 71 | *************/ 72 | 73 | /** 74 | * Singleton class instance 75 | */ 76 | public static Diagnostic_Camera instance = null; 77 | 78 | private Diagnostic diagnostic; 79 | 80 | /** 81 | * Current Cordova callback context (on this thread) 82 | */ 83 | protected CallbackContext currentContext; 84 | 85 | 86 | /************* 87 | * Public API 88 | ************/ 89 | 90 | /** 91 | * Constructor. 92 | */ 93 | public Diagnostic_Camera() {} 94 | 95 | /** 96 | * Sets the context of the Command. This can then be used to do things like 97 | * get file paths associated with the Activity. 98 | * 99 | * @param cordova The context of the main Activity. 100 | * @param webView The CordovaWebView Cordova is running in. 101 | */ 102 | public void initialize(CordovaInterface cordova, CordovaWebView webView) { 103 | Log.d(TAG, "initialize()"); 104 | instance = this; 105 | diagnostic = Diagnostic.getInstance(); 106 | 107 | super.initialize(cordova, webView); 108 | } 109 | 110 | 111 | /** 112 | * Executes the request and returns PluginResult. 113 | * 114 | * @param action The action to execute. 115 | * @param args JSONArry of arguments for the plugin. 116 | * @param callbackContext The callback id used when calling back into JavaScript. 117 | * @return True if the action was valid, false if not. 118 | */ 119 | public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { 120 | Diagnostic.instance.currentContext = currentContext = callbackContext; 121 | 122 | try { 123 | if(action.equals("isCameraPresent")) { 124 | callbackContext.success(isCameraPresent() ? 1 : 0); 125 | } else if(action.equals("requestCameraAuthorization")) { 126 | requestCameraAuthorization(args, callbackContext); 127 | } else if(action.equals("getCameraAuthorizationStatus")) { 128 | getCameraAuthorizationStatus(args, callbackContext); 129 | } else if(action.equals("getCameraAuthorizationStatuses")) { 130 | getCameraAuthorizationStatuses(args, callbackContext); 131 | }else { 132 | diagnostic.handleError("Invalid action"); 133 | return false; 134 | } 135 | }catch(Exception e ) { 136 | diagnostic.handleError("Exception occurred: ".concat(Objects.requireNonNull(e.getMessage()))); 137 | return false; 138 | } 139 | return true; 140 | } 141 | 142 | public boolean isCameraPresent() { 143 | int numberOfCameras = Camera.getNumberOfCameras(); 144 | PackageManager pm = this.cordova.getActivity().getPackageManager(); 145 | final boolean deviceHasCameraFlag = android.os.Build.VERSION.SDK_INT >= 32 ? pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY) : pm.hasSystemFeature(PackageManager.FEATURE_CAMERA); 146 | boolean result = (deviceHasCameraFlag && numberOfCameras>0 ); 147 | return result; 148 | } 149 | 150 | 151 | /************ 152 | * Internals 153 | ***********/ 154 | 155 | private String[] getPermissions(boolean storage){ 156 | String[] permissions = {cameraPermission}; 157 | if(storage){ 158 | permissions = Diagnostic.instance.concatStrings(permissions, storagePermissions); 159 | } 160 | return permissions; 161 | } 162 | 163 | private void requestCameraAuthorization(JSONArray args, CallbackContext callbackContext) throws Exception{ 164 | boolean storage = args.getBoolean(0); 165 | String[] permissions = getPermissions(storage); 166 | int requestId = Diagnostic.instance.storeContextByRequestId(callbackContext); 167 | Diagnostic.instance._requestRuntimePermissions(Diagnostic.instance.stringArrayToJsonArray(permissions), requestId); 168 | } 169 | 170 | private void getCameraAuthorizationStatuses(JSONArray args, CallbackContext callbackContext) throws Exception{ 171 | boolean storage = args.getBoolean(0); 172 | String[] permissions = getPermissions(storage); 173 | JSONObject statuses = Diagnostic.instance._getPermissionsAuthorizationStatus(permissions); 174 | callbackContext.success(statuses); 175 | } 176 | 177 | private void getCameraAuthorizationStatus(JSONArray args, CallbackContext callbackContext) throws Exception{ 178 | boolean storage = args.getBoolean(0); 179 | String[] permissions = getPermissions(storage); 180 | JSONObject statuses = Diagnostic.instance._getPermissionsAuthorizationStatus(permissions); 181 | 182 | String cameraStatus = getStatusForPermission(statuses, cameraPermission); 183 | 184 | String storageStatus = "DENIED"; 185 | if(storage) { 186 | if ( 187 | Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && 188 | ( 189 | getStatusForPermission(statuses, "READ_MEDIA_IMAGES").equals("GRANTED") || 190 | getStatusForPermission(statuses, "READ_MEDIA_VIDEO").equals("GRANTED") 191 | ) 192 | ) { 193 | // Full access on Android 13 (API level 33) or higher 194 | storageStatus = "GRANTED"; 195 | } else if ( 196 | Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && 197 | getStatusForPermission(statuses, "READ_MEDIA_VISUAL_USER_SELECTED").equals("GRANTED") 198 | ) { 199 | // Partial access on Android 14 (API level 34) or higher 200 | storageStatus = "LIMITED"; 201 | } else if ( 202 | getStatusForPermission(statuses, "READ_EXTERNAL_STORAGE").equals("GRANTED") 203 | ) { 204 | // Full access up to Android 12 (API level 32) 205 | storageStatus = "GRANTED"; 206 | } else { 207 | // Combination of statuses for all storage permissions for relevant API level 208 | storageStatus = combinePermissionStatuses(statuses); 209 | } 210 | } 211 | String status = cameraStatus; 212 | if(storage){ 213 | status = combinePermissionStatuses(new String[]{cameraStatus, storageStatus}); 214 | } 215 | 216 | callbackContext.success(status); 217 | } 218 | 219 | private String getStatusForPermission(JSONObject statuses, String permissionName) throws JSONException { 220 | return statuses.has(permissionName) ? statuses.getString(permissionName) : "DENIED"; 221 | } 222 | 223 | private boolean anyStatusIs(String status, String[] statuses){ 224 | for(String s : statuses){ 225 | if(s.equals(status)){ 226 | return true; 227 | } 228 | } 229 | return false; 230 | } 231 | 232 | private String combinePermissionStatuses(JSONObject permissionsStatuses) throws JSONException { 233 | String[] statuses = new String[storagePermissions.length]; 234 | for(int i = 0; i < storagePermissions.length; i++){ 235 | statuses[i] = getStatusForPermission(permissionsStatuses, storagePermissions[i]); 236 | } 237 | return combinePermissionStatuses(statuses); 238 | } 239 | 240 | private String combinePermissionStatuses(String[] statuses){ 241 | if(anyStatusIs("DENIED_ALWAYS", statuses)){ 242 | return "DENIED_ALWAYS"; 243 | }else if(anyStatusIs("LIMITED", statuses)){ 244 | return "LIMITED"; 245 | }else if(anyStatusIs("DENIED", statuses)){ 246 | return "DENIED"; 247 | }else if(anyStatusIs("GRANTED", statuses)){ 248 | return "GRANTED"; 249 | }else{ 250 | return "NOT_REQUESTED"; 251 | } 252 | } 253 | } 254 | -------------------------------------------------------------------------------- /src/android/Diagnostic_External_Storage.java: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an 14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, either express or implied. See the License for the 16 | specific language governing permissions and limitations 17 | under the License. 18 | */ 19 | package cordova.plugins; 20 | 21 | /* 22 | * Imports 23 | */ 24 | 25 | import android.os.Build; 26 | import android.os.Environment; 27 | import android.os.StatFs; 28 | import android.util.Log; 29 | 30 | import androidx.core.os.EnvironmentCompat; 31 | 32 | import org.apache.cordova.CallbackContext; 33 | import org.apache.cordova.CordovaInterface; 34 | import org.apache.cordova.CordovaPlugin; 35 | import org.apache.cordova.CordovaWebView; 36 | import org.json.JSONArray; 37 | import org.json.JSONException; 38 | import org.json.JSONObject; 39 | 40 | import java.io.File; 41 | import java.io.InputStream; 42 | import java.util.ArrayList; 43 | import java.util.List; 44 | 45 | /** 46 | * Diagnostic plugin implementation for Android 47 | */ 48 | public class Diagnostic_External_Storage extends CordovaPlugin{ 49 | 50 | 51 | /************* 52 | * Constants * 53 | *************/ 54 | 55 | /** 56 | * Tag for debug log messages 57 | */ 58 | public static final String TAG = "Diagnostic_External_Storage"; 59 | 60 | 61 | /************* 62 | * Variables * 63 | *************/ 64 | 65 | /** 66 | * Singleton class instance 67 | */ 68 | public static Diagnostic_External_Storage instance = null; 69 | 70 | private Diagnostic diagnostic; 71 | 72 | /** 73 | * Current Cordova callback context (on this thread) 74 | */ 75 | protected CallbackContext currentContext; 76 | 77 | 78 | /************* 79 | * Public API 80 | ************/ 81 | 82 | /** 83 | * Constructor. 84 | */ 85 | public Diagnostic_External_Storage() {} 86 | 87 | /** 88 | * Sets the context of the Command. This can then be used to do things like 89 | * get file paths associated with the Activity. 90 | * 91 | * @param cordova The context of the main Activity. 92 | * @param webView The CordovaWebView Cordova is running in. 93 | */ 94 | public void initialize(CordovaInterface cordova, CordovaWebView webView) { 95 | Log.d(TAG, "initialize()"); 96 | instance = this; 97 | diagnostic = Diagnostic.getInstance(); 98 | 99 | super.initialize(cordova, webView); 100 | } 101 | 102 | 103 | /** 104 | * Executes the request and returns PluginResult. 105 | * 106 | * @param action The action to execute. 107 | * @param args JSONArry of arguments for the plugin. 108 | * @param callbackContext The callback id used when calling back into JavaScript. 109 | * @return True if the action was valid, false if not. 110 | */ 111 | public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { 112 | Diagnostic.instance.currentContext = currentContext = callbackContext; 113 | 114 | try { 115 | if(action.equals("getExternalSdCardDetails")) { 116 | this.getExternalSdCardDetails(); 117 | } else { 118 | diagnostic.handleError("Invalid action"); 119 | return false; 120 | } 121 | }catch(Exception e ) { 122 | diagnostic.handleError("Exception occurred: ".concat(e.getMessage())); 123 | return false; 124 | } 125 | return true; 126 | } 127 | 128 | 129 | /************ 130 | * Internals 131 | ***********/ 132 | 133 | protected void getExternalSdCardDetails() throws JSONException { 134 | String[] storageDirectories = getStorageDirectories(); 135 | 136 | JSONArray details = new JSONArray(); 137 | for(int i=0; i results = new ArrayList(); 182 | 183 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //Method 1 for KitKat & above 184 | File[] externalDirs = this.cordova.getActivity().getApplicationContext().getExternalFilesDirs(null); 185 | 186 | for (File file : externalDirs) { 187 | if(file == null){ 188 | continue; 189 | } 190 | String applicationPath = file.getPath(); 191 | String rootPath = applicationPath.split("/Android")[0]; 192 | 193 | boolean addPath = false; 194 | 195 | if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 196 | addPath = Environment.isExternalStorageRemovable(file); 197 | } 198 | else{ 199 | addPath = Environment.MEDIA_MOUNTED.equals(EnvironmentCompat.getStorageState(file)); 200 | } 201 | 202 | if(addPath){ 203 | results.add(rootPath); 204 | results.add(applicationPath); 205 | } 206 | } 207 | } 208 | 209 | if(results.isEmpty()) { //Method 2 for all versions 210 | // better variation of: http://stackoverflow.com/a/40123073/5002496 211 | String output = ""; 212 | try { 213 | final Process process = new ProcessBuilder().command("mount | grep /dev/block/vold") 214 | .redirectErrorStream(true).start(); 215 | process.waitFor(); 216 | final InputStream is = process.getInputStream(); 217 | final byte[] buffer = new byte[1024]; 218 | while (is.read(buffer) != -1) { 219 | output = output + new String(buffer); 220 | } 221 | is.close(); 222 | } catch (final Exception e) { 223 | e.printStackTrace(); 224 | } 225 | if(!output.trim().isEmpty()) { 226 | String devicePoints[] = output.split("\n"); 227 | for(String voldPoint: devicePoints) { 228 | results.add(voldPoint.split(" ")[2]); 229 | } 230 | } 231 | } 232 | 233 | //Below few lines is to remove paths which may not be external memory card, like OTG (feel free to comment them out) 234 | if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 235 | for (int i = 0; i < results.size(); i++) { 236 | if (!results.get(i).toLowerCase().matches(".*[0-9a-f]{4}[-][0-9a-f]{4}.*")) { 237 | diagnostic.logDebug(results.get(i) + " might not be extSDcard"); 238 | results.remove(i--); 239 | } 240 | } 241 | } else { 242 | for (int i = 0; i < results.size(); i++) { 243 | if (!results.get(i).toLowerCase().contains("ext") && !results.get(i).toLowerCase().contains("sdcard")) { 244 | diagnostic.logDebug(results.get(i)+" might not be extSDcard"); 245 | results.remove(i--); 246 | } 247 | } 248 | } 249 | 250 | String[] storageDirectories = new String[results.size()]; 251 | for(int i=0; i= 16) { 183 | settingsIntent = new Intent(android.provider.Settings.ACTION_NFC_SETTINGS); 184 | } 185 | cordova.getActivity().startActivity(settingsIntent); 186 | } 187 | 188 | public boolean isNFCPresent() { 189 | boolean result = false; 190 | try { 191 | NfcAdapter adapter = nfcManager.getDefaultAdapter(); 192 | result = adapter != null; 193 | }catch(Exception e){ 194 | diagnostic.logError(e.getMessage()); 195 | } 196 | return result; 197 | } 198 | 199 | public boolean isNFCEnabled() { 200 | boolean result = false; 201 | try { 202 | NfcAdapter adapter = nfcManager.getDefaultAdapter(); 203 | result = adapter != null && adapter.isEnabled(); 204 | }catch(Exception e){ 205 | diagnostic.logError(e.getMessage()); 206 | } 207 | return result; 208 | } 209 | 210 | public boolean isNFCAvailable() { 211 | boolean result = isNFCPresent() && isNFCEnabled(); 212 | return result; 213 | } 214 | 215 | public void notifyNFCStateChange(int stateValue){ 216 | String newState = getNFCState(stateValue); 217 | try { 218 | if(newState != currentNFCState){ 219 | diagnostic.logDebug("NFC state changed to: " + newState); 220 | diagnostic.executePluginJavascript("nfc._onNFCStateChange(\"" + newState +"\");"); 221 | currentNFCState = newState; 222 | } 223 | }catch(Exception e){ 224 | diagnostic.logError("Error retrieving current NFC state on state change: "+e.toString()); 225 | } 226 | } 227 | 228 | public String getNFCState(int stateValue){ 229 | 230 | String state; 231 | switch(stateValue){ 232 | case NFC_STATE_VALUE_OFF: 233 | state = NFC_STATE_OFF; 234 | break; 235 | case NFC_STATE_VALUE_TURNING_ON: 236 | state = NFC_STATE_TURNING_ON; 237 | break; 238 | case NFC_STATE_VALUE_ON: 239 | state = NFC_STATE_ON; 240 | break; 241 | case NFC_STATE_VALUE_TURNING_OFF: 242 | state = NFC_STATE_TURNING_OFF; 243 | break; 244 | default: 245 | state = NFC_STATE_UNKNOWN; 246 | } 247 | return state; 248 | } 249 | 250 | /************ 251 | * Overrides 252 | ***********/ 253 | 254 | protected final BroadcastReceiver NFCStateChangedReceiver = new BroadcastReceiver() { 255 | @Override 256 | public void onReceive(Context context, Intent intent) { 257 | try { 258 | final String action = intent.getAction(); 259 | if(instance != null && action.equals(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)){ 260 | 261 | Log.v(TAG, "onReceiveNFCStateChange"); 262 | final int stateValue = intent.getIntExtra(EXTRA_ADAPTER_STATE, -1); 263 | instance.notifyNFCStateChange(stateValue); 264 | } 265 | } catch (Exception e) { 266 | diagnostic.logError("Error receiving NFC state change: "+e.toString()); 267 | } 268 | } 269 | }; 270 | } -------------------------------------------------------------------------------- /src/android/Diagnostic_Notifications.java: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an 14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, either express or implied. See the License for the 16 | specific language governing permissions and limitations 17 | under the License. 18 | */ 19 | package cordova.plugins; 20 | 21 | /* 22 | * Imports 23 | */ 24 | 25 | import android.content.Context; 26 | import android.content.Intent; 27 | import android.content.pm.PackageManager; 28 | import android.net.Uri; 29 | import android.os.Build; 30 | import android.provider.Settings; 31 | import android.util.Log; 32 | 33 | import org.apache.cordova.CallbackContext; 34 | import org.apache.cordova.CordovaInterface; 35 | import org.apache.cordova.CordovaPlugin; 36 | import org.apache.cordova.CordovaWebView; 37 | import org.json.JSONArray; 38 | import org.json.JSONException; 39 | 40 | import androidx.core.app.NotificationManagerCompat; 41 | 42 | /** 43 | * Diagnostic plugin implementation for Android 44 | */ 45 | public class Diagnostic_Notifications extends CordovaPlugin{ 46 | 47 | 48 | /************* 49 | * Constants * 50 | *************/ 51 | 52 | 53 | /** 54 | * Tag for debug log messages 55 | */ 56 | public static final String TAG = "Diagnostic_Notifications"; 57 | 58 | 59 | /************* 60 | * Variables * 61 | *************/ 62 | 63 | /** 64 | * Singleton class instance 65 | */ 66 | public static Diagnostic_Notifications instance = null; 67 | 68 | private Diagnostic diagnostic; 69 | 70 | /** 71 | * Current Cordova callback context (on this thread) 72 | */ 73 | protected CallbackContext currentContext; 74 | 75 | 76 | /************* 77 | * Public API 78 | ************/ 79 | 80 | /** 81 | * Constructor. 82 | */ 83 | public Diagnostic_Notifications() {} 84 | 85 | /** 86 | * Sets the context of the Command. This can then be used to do things like 87 | * get file paths associated with the Activity. 88 | * 89 | * @param cordova The context of the main Activity. 90 | * @param webView The CordovaWebView Cordova is running in. 91 | */ 92 | public void initialize(CordovaInterface cordova, CordovaWebView webView) { 93 | Log.d(TAG, "initialize()"); 94 | instance = this; 95 | diagnostic = Diagnostic.getInstance(); 96 | 97 | super.initialize(cordova, webView); 98 | } 99 | 100 | 101 | /** 102 | * Executes the request and returns PluginResult. 103 | * 104 | * @param action The action to execute. 105 | * @param args JSONArry of arguments for the plugin. 106 | * @param callbackContext The callback id used when calling back into JavaScript. 107 | * @return True if the action was valid, false if not. 108 | */ 109 | public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { 110 | Diagnostic.instance.currentContext = currentContext = callbackContext; 111 | 112 | try { 113 | if(action.equals("isRemoteNotificationsEnabled")) { 114 | callbackContext.success(isRemoteNotificationsEnabled() ? 1 : 0); 115 | } else if(action.equals("switchToNotificationSettings")) { 116 | switchToNotificationSettings(); 117 | callbackContext.success(); 118 | } else { 119 | diagnostic.handleError("Invalid action"); 120 | return false; 121 | } 122 | }catch(Exception e ) { 123 | diagnostic.handleError("Exception occurred: ".concat(e.getMessage())); 124 | return false; 125 | } 126 | return true; 127 | } 128 | 129 | 130 | public boolean isRemoteNotificationsEnabled() { 131 | NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this.cordova.getActivity().getApplicationContext()); 132 | boolean result = notificationManagerCompat.areNotificationsEnabled(); 133 | return result; 134 | } 135 | 136 | public void switchToNotificationSettings() { 137 | Context context = this.cordova.getActivity().getApplicationContext(); 138 | Intent settingsIntent = new Intent(); 139 | String packageName = context.getPackageName(); 140 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 141 | diagnostic.logDebug("Switch to notification Settings"); 142 | settingsIntent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS); 143 | settingsIntent.putExtra(Settings.EXTRA_APP_PACKAGE, packageName); 144 | } else { 145 | settingsIntent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); 146 | settingsIntent.setData(Uri.parse("package:" + packageName)); 147 | diagnostic.logDebug("Switch to notification Settings: Only possible on android O or above. Falling back to application details"); 148 | } 149 | cordova.getActivity().startActivity(settingsIntent); 150 | } 151 | 152 | /************ 153 | * Internals 154 | ***********/ 155 | 156 | 157 | } 158 | -------------------------------------------------------------------------------- /src/android/Diagnostic_Wifi.java: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an 14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, either express or implied. See the License for the 16 | specific language governing permissions and limitations 17 | under the License. 18 | */ 19 | package cordova.plugins; 20 | 21 | /* 22 | * Imports 23 | */ 24 | 25 | import android.content.Context; 26 | import android.content.Intent; 27 | import android.net.wifi.WifiManager; 28 | import android.provider.Settings; 29 | import android.util.Log; 30 | 31 | import org.apache.cordova.CallbackContext; 32 | import org.apache.cordova.CordovaInterface; 33 | import org.apache.cordova.CordovaPlugin; 34 | import org.apache.cordova.CordovaWebView; 35 | import org.json.JSONArray; 36 | import org.json.JSONException; 37 | 38 | /** 39 | * Diagnostic plugin implementation for Android 40 | */ 41 | public class Diagnostic_Wifi extends CordovaPlugin{ 42 | 43 | 44 | /************* 45 | * Constants * 46 | *************/ 47 | 48 | 49 | /** 50 | * Tag for debug log messages 51 | */ 52 | public static final String TAG = "Diagnostic_Wifi"; 53 | 54 | 55 | /************* 56 | * Variables * 57 | *************/ 58 | 59 | /** 60 | * Singleton class instance 61 | */ 62 | public static Diagnostic_Wifi instance = null; 63 | 64 | private Diagnostic diagnostic; 65 | 66 | /** 67 | * Current Cordova callback context (on this thread) 68 | */ 69 | protected CallbackContext currentContext; 70 | 71 | 72 | /************* 73 | * Public API 74 | ************/ 75 | 76 | /** 77 | * Constructor. 78 | */ 79 | public Diagnostic_Wifi() {} 80 | 81 | /** 82 | * Sets the context of the Command. This can then be used to do things like 83 | * get file paths associated with the Activity. 84 | * 85 | * @param cordova The context of the main Activity. 86 | * @param webView The CordovaWebView Cordova is running in. 87 | */ 88 | public void initialize(CordovaInterface cordova, CordovaWebView webView) { 89 | Log.d(TAG, "initialize()"); 90 | instance = this; 91 | diagnostic = Diagnostic.getInstance(); 92 | 93 | super.initialize(cordova, webView); 94 | } 95 | 96 | 97 | /** 98 | * Executes the request and returns PluginResult. 99 | * 100 | * @param action The action to execute. 101 | * @param args JSONArry of arguments for the plugin. 102 | * @param callbackContext The callback id used when calling back into JavaScript. 103 | * @return True if the action was valid, false if not. 104 | */ 105 | public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { 106 | Diagnostic.instance.currentContext = currentContext = callbackContext; 107 | 108 | try { 109 | if (action.equals("switchToWifiSettings")){ 110 | switchToWifiSettings(); 111 | callbackContext.success(); 112 | } else if(action.equals("isWifiAvailable")) { 113 | callbackContext.success(isWifiAvailable() ? 1 : 0); 114 | } else if(action.equals("setWifiState")) { 115 | setWifiState(args.getBoolean(0)); 116 | callbackContext.success(); 117 | } else { 118 | diagnostic.handleError("Invalid action"); 119 | return false; 120 | } 121 | }catch(Exception e ) { 122 | diagnostic.handleError("Exception occurred: ".concat(e.getMessage())); 123 | return false; 124 | } 125 | return true; 126 | } 127 | 128 | public boolean isWifiAvailable() { 129 | WifiManager wifiManager = (WifiManager) this.cordova.getActivity().getApplicationContext().getSystemService(Context.WIFI_SERVICE); 130 | boolean result = wifiManager.isWifiEnabled(); 131 | return result; 132 | } 133 | 134 | public void switchToWifiSettings() { 135 | diagnostic.logDebug("Switch to Wifi Settings"); 136 | Intent settingsIntent = new Intent(Settings.ACTION_WIFI_SETTINGS); 137 | cordova.getActivity().startActivity(settingsIntent); 138 | } 139 | 140 | public void setWifiState(boolean enable) { 141 | WifiManager wifiManager = (WifiManager) this.cordova.getActivity().getApplicationContext().getSystemService(Context.WIFI_SERVICE); 142 | if (enable && !wifiManager.isWifiEnabled()) { 143 | wifiManager.setWifiEnabled(true); 144 | } else if (!enable && wifiManager.isWifiEnabled()) { 145 | wifiManager.setWifiEnabled(false); 146 | } 147 | } 148 | 149 | 150 | /************ 151 | * Internals 152 | ***********/ 153 | 154 | 155 | } 156 | -------------------------------------------------------------------------------- /src/ios/Diagnostic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic.h 3 | * Diagnostic Plugin - Core Module 4 | * 5 | * Copyright (c) 2015 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import 10 | #import 11 | #import 12 | 13 | #import 14 | #import 15 | #import 16 | 17 | // Public constants 18 | extern NSString*const UNKNOWN; 19 | 20 | extern NSString*const AUTHORIZATION_NOT_DETERMINED; 21 | extern NSString*const AUTHORIZATION_DENIED; 22 | extern NSString*const AUTHORIZATION_GRANTED; 23 | extern NSString*const AUTHORIZATION_PROVISIONAL; 24 | extern NSString*const AUTHORIZATION_EPHEMERAL; 25 | extern NSString*const AUTHORIZATION_LIMITED; 26 | 27 | @interface Diagnostic : CDVPlugin 28 | 29 | @property (nonatomic) float osVersion; 30 | @property (nonatomic) BOOL debugEnabled; 31 | 32 | // Plugin API 33 | - (void) enableDebug: (CDVInvokedUrlCommand*)command; 34 | - (void) switchToSettings: (CDVInvokedUrlCommand*)command; 35 | - (void) getBackgroundRefreshStatus: (CDVInvokedUrlCommand*)command; 36 | - (void) getArchitecture: (CDVInvokedUrlCommand*)command; 37 | - (void) getCurrentBatteryLevel: (CDVInvokedUrlCommand*)command; 38 | - (void) getDeviceOSVersion: (CDVInvokedUrlCommand*)command; 39 | - (void) getBuildOSVersion: (CDVInvokedUrlCommand*)command; 40 | - (void) isMobileDataAuthorized: (CDVInvokedUrlCommand*)command; 41 | - (void) isAccessibilityModeEnabled: (CDVInvokedUrlCommand*)command; 42 | - (void) isDebugBuild: (CDVInvokedUrlCommand*)command; 43 | 44 | // Utilities 45 | + (id) getInstance; 46 | - (void) sendPluginResult: (CDVPluginResult*)result :(CDVInvokedUrlCommand*)command; 47 | - (void) sendPluginResultSuccess:(CDVInvokedUrlCommand*)command; 48 | - (void) sendPluginNoResultAndKeepCallback:(CDVInvokedUrlCommand*)command; 49 | - (void) sendPluginResultBool: (BOOL)result :(CDVInvokedUrlCommand*)command; 50 | - (void) sendPluginResultString: (NSString*)result :(CDVInvokedUrlCommand*)command; 51 | - (void) sendPluginError: (NSString*) errorMessage :(CDVInvokedUrlCommand*)command; 52 | - (void) handlePluginException: (NSException*) exception :(CDVInvokedUrlCommand*)command; 53 | - (void)executeGlobalJavascript: (NSString*)jsString; 54 | - (NSString*) arrayToJsonString:(NSArray*)inputArray; 55 | - (NSString*) objectToJsonString:(NSDictionary*)inputObject; 56 | - (NSArray*) jsonStringToArray:(NSString*)jsonStr; 57 | - (NSDictionary*) jsonStringToDictionary:(NSString*)jsonStr; 58 | - (bool)isNull: (NSString*)str; 59 | - (void)logDebug: (NSString*)msg; 60 | - (void)logError: (NSString*)msg; 61 | - (NSString*)escapeDoubleQuotes: (NSString*)str; 62 | - (void) setSetting: (NSString*)key forValue:(id)value; 63 | - (id) getSetting: (NSString*) key; 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Bluetooth.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic_Bluetooth.h 3 | * Diagnostic Plugin - Bluetooth Module 4 | * 5 | * Copyright (c) 2018 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import 10 | #import 11 | #import "Diagnostic.h" 12 | #import 13 | 14 | 15 | @interface Diagnostic_Bluetooth : CDVPlugin 16 | 17 | @property (nonatomic, retain) CBCentralManager* bluetoothManager; 18 | 19 | - (void) isBluetoothAvailable: (CDVInvokedUrlCommand*)command; 20 | - (void) getBluetoothState: (CDVInvokedUrlCommand*)command; 21 | - (void) requestBluetoothAuthorization: (CDVInvokedUrlCommand*)command; 22 | - (void) ensureBluetoothManager: (CDVInvokedUrlCommand*)command; 23 | - (void) getAuthorizationStatus: (CDVInvokedUrlCommand*)command; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Bluetooth.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic_Bluetooth.m 3 | * Diagnostic Plugin - Bluetooth Module 4 | * 5 | * Copyright (c) 2018 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import "Diagnostic_Bluetooth.h" 10 | 11 | @implementation Diagnostic_Bluetooth 12 | 13 | // Internal reference to Diagnostic singleton instance 14 | static Diagnostic* diagnostic; 15 | 16 | // Internal constants 17 | static NSString*const LOG_TAG = @"Diagnostic_Bluetooth[native]"; 18 | 19 | - (void)pluginInitialize { 20 | 21 | [super pluginInitialize]; 22 | 23 | diagnostic = [Diagnostic getInstance]; 24 | } 25 | 26 | /********************************/ 27 | #pragma mark - Plugin API 28 | /********************************/ 29 | 30 | - (void) isBluetoothAvailable: (CDVInvokedUrlCommand*)command 31 | { 32 | [self.commandDelegate runInBackground:^{ 33 | @try { 34 | NSString* state = [self getBluetoothState]; 35 | bool bluetoothEnabled; 36 | if([state isEqual: @"powered_on"]){ 37 | bluetoothEnabled = true; 38 | }else{ 39 | bluetoothEnabled = false; 40 | } 41 | [diagnostic sendPluginResultBool:bluetoothEnabled :command]; 42 | } 43 | @catch (NSException *exception) { 44 | [diagnostic handlePluginException:exception :command]; 45 | } 46 | }]; 47 | } 48 | 49 | - (void) getBluetoothState: (CDVInvokedUrlCommand*)command 50 | { 51 | [self.commandDelegate runInBackground:^{ 52 | @try { 53 | NSString* state = [self getBluetoothState]; 54 | [diagnostic logDebug:[NSString stringWithFormat:@"Bluetooth state is: %@", state]]; 55 | [diagnostic sendPluginResultString:state:command]; 56 | } 57 | @catch (NSException *exception) { 58 | [diagnostic handlePluginException:exception :command]; 59 | } 60 | }]; 61 | 62 | } 63 | 64 | - (void) requestBluetoothAuthorization: (CDVInvokedUrlCommand*)command 65 | { 66 | [self.commandDelegate runInBackground:^{ 67 | @try { 68 | 69 | NSString* authState = [self getAuthorizationStatus]; 70 | 71 | if([authState isEqual:AUTHORIZATION_GRANTED]){ 72 | [diagnostic sendPluginError:@"Bluetooth authorization is already granted" :command]; 73 | }else if([authState isEqual:AUTHORIZATION_DENIED]){ 74 | [diagnostic sendPluginError:@"Bluetooth authorization has been denied" :command]; 75 | }else{ // AUTHORIZATION_NOT_DETERMINED 76 | [self ensureBluetoothManager]; // invoke Bluetooth manager to trigger permission dialog 77 | [diagnostic sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] :command]; 78 | } 79 | } 80 | @catch (NSException *exception) { 81 | [diagnostic handlePluginException:exception :command]; 82 | } 83 | }]; 84 | } 85 | 86 | - (void) ensureBluetoothManager: (CDVInvokedUrlCommand*)command 87 | { 88 | [self.commandDelegate runInBackground:^{ 89 | @try { 90 | [self ensureBluetoothManager]; 91 | [diagnostic sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] :command]; 92 | } 93 | @catch (NSException *exception) { 94 | [diagnostic handlePluginException:exception :command]; 95 | } 96 | }]; 97 | 98 | } 99 | 100 | - (void) getAuthorizationStatus: (CDVInvokedUrlCommand*)command { 101 | [self.commandDelegate runInBackground:^{ 102 | @try { 103 | NSString* authState = [self getAuthorizationStatus]; 104 | [diagnostic sendPluginResultString:authState :command]; 105 | }@catch (NSException *exception) { 106 | [diagnostic handlePluginException:exception :command]; 107 | } 108 | }]; 109 | } 110 | 111 | /********************************/ 112 | #pragma mark - Internals 113 | /********************************/ 114 | 115 | - (NSString*)getBluetoothState{ 116 | NSString* state; 117 | NSString* description; 118 | 119 | [self ensureBluetoothManager]; 120 | switch(self.bluetoothManager.state) 121 | { 122 | 123 | case CBManagerStateResetting: 124 | state = @"resetting"; 125 | description =@"The connection with the system service was momentarily lost, update imminent."; 126 | break; 127 | 128 | case CBManagerStateUnsupported: 129 | state = @"unsupported"; 130 | description = @"The platform doesn't support Bluetooth Low Energy."; 131 | break; 132 | 133 | case CBManagerStateUnauthorized: 134 | state = @"unauthorized"; 135 | description = @"The app is not authorized to use Bluetooth Low Energy."; 136 | break; 137 | 138 | case CBManagerStatePoweredOff: 139 | state = @"powered_off"; 140 | description = @"Bluetooth is currently powered off."; 141 | break; 142 | 143 | case CBManagerStatePoweredOn: 144 | state = @"powered_on"; 145 | description = @"Bluetooth is currently powered on and available to use."; 146 | break; 147 | default: 148 | state = UNKNOWN; 149 | description = @"State unknown, update imminent."; 150 | break; 151 | } 152 | [diagnostic logDebug:[NSString stringWithFormat:@"Bluetooth state changed: %@",description]]; 153 | 154 | 155 | return state; 156 | } 157 | 158 | - (void) ensureBluetoothManager { 159 | if(![self.bluetoothManager isKindOfClass:[CBCentralManager class]]){ 160 | self.bluetoothManager = [[CBCentralManager alloc] 161 | initWithDelegate:self 162 | queue:dispatch_get_main_queue() 163 | options:@{CBCentralManagerOptionShowPowerAlertKey: @(NO)}]; 164 | [self centralManagerDidUpdateState:self.bluetoothManager]; // Send initial state 165 | } 166 | } 167 | 168 | // https://stackoverflow.com/q/57238647/777265 169 | - (NSString*) getAuthorizationStatus { 170 | NSString* authState; 171 | if (@available(iOS 13.0, *)){ 172 | CBManagerAuthorization authorization; 173 | if(@available(iOS 13.1, *)){ 174 | authorization = CBCentralManager.authorization; 175 | }else{ 176 | // iOS 13.0 requires BT manager to be initialized in order to check authorization which results in BT permissions dialog if not already authorized 177 | [self ensureBluetoothManager]; 178 | authorization = [self.bluetoothManager authorization]; 179 | } 180 | 181 | switch(authorization){ 182 | case CBManagerAuthorizationAllowedAlways: 183 | authState = AUTHORIZATION_GRANTED; 184 | break; 185 | case CBManagerAuthorizationDenied: 186 | authState = AUTHORIZATION_DENIED; 187 | break; 188 | case CBManagerAuthorizationRestricted: 189 | authState = AUTHORIZATION_DENIED; 190 | break; 191 | case CBManagerAuthorizationNotDetermined: 192 | authState = AUTHORIZATION_NOT_DETERMINED; 193 | break; 194 | } 195 | }else{ 196 | // Device is running iOS <13.0 so doesn't require Bluetooth permission at run-time 197 | authState = AUTHORIZATION_GRANTED; 198 | } 199 | return authState; 200 | } 201 | 202 | /********************************/ 203 | #pragma mark - CBCentralManagerDelegate 204 | /********************************/ 205 | 206 | - (void) centralManagerDidUpdateState:(CBCentralManager *)central { 207 | NSString* state = [self getBluetoothState]; 208 | NSString* jsString = [NSString stringWithFormat:@"cordova.plugins.diagnostic.bluetooth._onBluetoothStateChange(\"%@\");", state]; 209 | [diagnostic executeGlobalJavascript:jsString]; 210 | } 211 | 212 | @end 213 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Calendar.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic_Calendar.h 3 | * Diagnostic Plugin - Calendar Module 4 | * 5 | * Copyright (c) 2018 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import 10 | #import 11 | #import "Diagnostic.h" 12 | 13 | #import 14 | 15 | 16 | @interface Diagnostic_Calendar : CDVPlugin 17 | 18 | @property (nonatomic) EKEventStore *eventStore; 19 | 20 | - (void) getCalendarAuthorizationStatus: (CDVInvokedUrlCommand*)command; 21 | - (void) isCalendarAuthorized: (CDVInvokedUrlCommand*)command; 22 | - (void) requestCalendarAuthorization: (CDVInvokedUrlCommand*)command; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Calendar.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic_Calendar.m 3 | * Diagnostic Plugin - Calendar Module 4 | * 5 | * Copyright (c) 2018 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import "Diagnostic_Calendar.h" 10 | 11 | 12 | @implementation Diagnostic_Calendar 13 | 14 | // Internal reference to Diagnostic singleton instance 15 | static Diagnostic* diagnostic; 16 | 17 | // Internal constants 18 | static NSString*const LOG_TAG = @"Diagnostic_Calendar[native]"; 19 | 20 | - (void)pluginInitialize { 21 | 22 | [super pluginInitialize]; 23 | 24 | diagnostic = [Diagnostic getInstance]; 25 | 26 | } 27 | 28 | /********************************/ 29 | #pragma mark - Plugin API 30 | /********************************/ 31 | 32 | - (void) getCalendarAuthorizationStatus: (CDVInvokedUrlCommand*)command 33 | { 34 | [self.commandDelegate runInBackground:^{ 35 | @try { 36 | NSString* status; 37 | 38 | EKAuthorizationStatus authStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent]; 39 | 40 | if(authStatus == EKAuthorizationStatusDenied || authStatus == EKAuthorizationStatusRestricted){ 41 | status = AUTHORIZATION_DENIED; 42 | }else if(authStatus == EKAuthorizationStatusNotDetermined){ 43 | status = AUTHORIZATION_NOT_DETERMINED; 44 | }else if(authStatus == EKAuthorizationStatusAuthorized){ 45 | status = AUTHORIZATION_GRANTED; 46 | } 47 | [diagnostic logDebug:[NSString stringWithFormat:@"Calendar event authorization status is: %@", status]]; 48 | [diagnostic sendPluginResultString:status:command]; 49 | } 50 | @catch (NSException *exception) { 51 | [diagnostic handlePluginException:exception :command]; 52 | } 53 | }]; 54 | } 55 | 56 | - (void) isCalendarAuthorized: (CDVInvokedUrlCommand*)command 57 | { 58 | [self.commandDelegate runInBackground:^{ 59 | @try { 60 | EKAuthorizationStatus authStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent]; 61 | [diagnostic sendPluginResultBool:authStatus == EKAuthorizationStatusAuthorized:command]; 62 | } 63 | @catch (NSException *exception) { 64 | [diagnostic handlePluginException:exception :command]; 65 | } 66 | }]; 67 | } 68 | 69 | - (void) requestCalendarAuthorization: (CDVInvokedUrlCommand*)command 70 | { 71 | [self.commandDelegate runInBackground:^{ 72 | @try { 73 | 74 | if (!self.eventStore) { 75 | self.eventStore = [EKEventStore new]; 76 | } 77 | 78 | [self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { 79 | [diagnostic logDebug:[NSString stringWithFormat:@"Access request to calendar events: %d", granted]]; 80 | [diagnostic sendPluginResultBool:granted:command]; 81 | }]; 82 | } 83 | @catch (NSException *exception) { 84 | [diagnostic handlePluginException:exception :command]; 85 | } 86 | }]; 87 | } 88 | 89 | /********************************/ 90 | #pragma mark - Internals 91 | /********************************/ 92 | 93 | 94 | @end 95 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Camera.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic_Camera.h 3 | * Diagnostic Plugin - Camera Module 4 | * 5 | * Copyright (c) 2018 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import 10 | #import 11 | #import "Diagnostic.h" 12 | 13 | #import 14 | #import 15 | #import 16 | 17 | 18 | @interface Diagnostic_Camera : CDVPlugin 19 | 20 | - (void) isCameraAvailable: (CDVInvokedUrlCommand*)command; 21 | - (void) isCameraPresent: (CDVInvokedUrlCommand*)command; 22 | - (void) isCameraAuthorized: (CDVInvokedUrlCommand*)command; 23 | - (void) getCameraAuthorizationStatus: (CDVInvokedUrlCommand*)command; 24 | - (void) requestCameraAuthorization: (CDVInvokedUrlCommand*)command; 25 | - (void) isCameraRollAuthorized: (CDVInvokedUrlCommand*)command; 26 | - (void) getCameraRollAuthorizationStatus: (CDVInvokedUrlCommand*)command; 27 | - (void) presentLimitedLibraryPicker: (CDVInvokedUrlCommand*)command; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Camera.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic_Camera.m 3 | * Diagnostic Plugin - Camera Module 4 | * 5 | * Copyright (c) 2018 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import "Diagnostic_Camera.h" 10 | 11 | 12 | @implementation Diagnostic_Camera 13 | 14 | // Internal reference to Diagnostic singleton instance 15 | static Diagnostic* diagnostic; 16 | 17 | // Internal constants 18 | static NSString*const LOG_TAG = @"Diagnostic_Camera[native]"; 19 | 20 | static NSString*const PHOTOLIBRARY_ACCESS_LEVEL_ADD_ONLY = @"add_only"; 21 | static NSString*const PHOTOLIBRARY_ACCESS_LEVEL_READ_WRITE = @"read_write"; 22 | 23 | - (void)pluginInitialize { 24 | 25 | [super pluginInitialize]; 26 | 27 | diagnostic = [Diagnostic getInstance]; 28 | } 29 | 30 | /********************************/ 31 | #pragma mark - Plugin API 32 | /********************************/ 33 | 34 | - (void) isCameraAvailable: (CDVInvokedUrlCommand*)command 35 | { 36 | [self.commandDelegate runInBackground:^{ 37 | @try { 38 | [diagnostic sendPluginResultBool:[self isCameraPresent] && [self isCameraAuthorized] :command]; 39 | } 40 | @catch (NSException *exception) { 41 | [diagnostic handlePluginException:exception :command]; 42 | } 43 | }]; 44 | } 45 | 46 | - (void) isCameraPresent: (CDVInvokedUrlCommand*)command 47 | { 48 | [self.commandDelegate runInBackground:^{ 49 | @try { 50 | [diagnostic sendPluginResultBool:[self isCameraPresent] :command]; 51 | } 52 | @catch (NSException *exception) { 53 | [diagnostic handlePluginException:exception :command]; 54 | } 55 | }]; 56 | } 57 | 58 | - (void) isCameraAuthorized: (CDVInvokedUrlCommand*)command 59 | { 60 | [self.commandDelegate runInBackground:^{ 61 | @try { 62 | [diagnostic sendPluginResultBool:[self isCameraAuthorized] :command]; 63 | } 64 | @catch (NSException *exception) { 65 | [diagnostic handlePluginException:exception :command]; 66 | } 67 | }]; 68 | } 69 | 70 | - (void) getCameraAuthorizationStatus: (CDVInvokedUrlCommand*)command 71 | { 72 | [self.commandDelegate runInBackground:^{ 73 | @try { 74 | NSString* status; 75 | AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; 76 | 77 | if(authStatus == AVAuthorizationStatusDenied || authStatus == AVAuthorizationStatusRestricted){ 78 | status = AUTHORIZATION_DENIED; 79 | }else if(authStatus == AVAuthorizationStatusNotDetermined){ 80 | status = AUTHORIZATION_NOT_DETERMINED; 81 | }else if(authStatus == AVAuthorizationStatusAuthorized){ 82 | status = AUTHORIZATION_GRANTED; 83 | } 84 | [diagnostic logDebug:[NSString stringWithFormat:@"Camera authorization status is: %@", status]]; 85 | [diagnostic sendPluginResultString:status:command]; 86 | } 87 | @catch (NSException *exception) { 88 | [diagnostic handlePluginException:exception :command]; 89 | } 90 | }]; 91 | } 92 | 93 | - (void) requestCameraAuthorization: (CDVInvokedUrlCommand*)command 94 | { 95 | [self.commandDelegate runInBackground:^{ 96 | @try { 97 | [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { 98 | [diagnostic sendPluginResultBool:granted :command]; 99 | }]; 100 | } 101 | @catch (NSException *exception) { 102 | [diagnostic handlePluginException:exception :command]; 103 | } 104 | }]; 105 | } 106 | 107 | - (void) isCameraRollAuthorized: (CDVInvokedUrlCommand*)command 108 | { 109 | [self.commandDelegate runInBackground:^{ 110 | @try { 111 | bool isAuthorized = [[self resolveCameraRollAuthorizationStatusFromCommand:command] isEqual: AUTHORIZATION_GRANTED] || [[self resolveCameraRollAuthorizationStatusFromCommand:command] isEqual: AUTHORIZATION_LIMITED]; 112 | [diagnostic sendPluginResultBool:isAuthorized:command]; 113 | } 114 | @catch (NSException *exception) { 115 | [diagnostic handlePluginException:exception :command]; 116 | } 117 | }]; 118 | } 119 | 120 | - (void) getCameraRollAuthorizationStatus: (CDVInvokedUrlCommand*)command 121 | { 122 | [self.commandDelegate runInBackground:^{ 123 | @try { 124 | NSString* status = [self resolveCameraRollAuthorizationStatusFromCommand:command]; 125 | [diagnostic logDebug:[NSString stringWithFormat:@"Camera Roll authorization status is: %@", status]]; 126 | [diagnostic sendPluginResultString:status:command]; 127 | } 128 | @catch (NSException *exception) { 129 | [diagnostic handlePluginException:exception :command]; 130 | } 131 | }]; 132 | } 133 | 134 | - (void) requestCameraRollAuthorization: (CDVInvokedUrlCommand*)command 135 | { 136 | [self.commandDelegate runInBackground:^{ 137 | @try { 138 | if (@available(iOS 14.0, *)){ 139 | PHAccessLevel ph_accessLevel = [self resolveAccessLevelFromArgument:[command.arguments objectAtIndex:0]]; 140 | 141 | [PHPhotoLibrary requestAuthorizationForAccessLevel:ph_accessLevel handler:^(PHAuthorizationStatus authStatus) { 142 | NSString* status = [self getCameraRollAuthorizationStatusAsString:authStatus]; 143 | [diagnostic sendPluginResultString:status:command]; 144 | }]; 145 | 146 | }else{ 147 | [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus authStatus) { 148 | NSString* status = [self getCameraRollAuthorizationStatusAsString:authStatus]; 149 | [diagnostic sendPluginResultString:status:command]; 150 | }]; 151 | } 152 | } 153 | @catch (NSException *exception) { 154 | [diagnostic handlePluginException:exception :command]; 155 | } 156 | }]; 157 | } 158 | 159 | - (void) presentLimitedLibraryPicker: (CDVInvokedUrlCommand*)command 160 | { 161 | [self.commandDelegate runInBackground:^{ 162 | @try { 163 | NSString* authStatus = [self resolveCameraRollAuthorizationStatusFromString:PHOTOLIBRARY_ACCESS_LEVEL_ADD_ONLY]; 164 | if(![authStatus isEqualToString:AUTHORIZATION_LIMITED]){ 165 | [diagnostic sendPluginError:[NSString stringWithFormat:@"Limited photo library access UI can only be shown when auth status is AUTHORIZATION_LIMITED but auth status is %@", authStatus]:command]; 166 | } 167 | else if (@available(iOS 15.0, *)){ 168 | [[PHPhotoLibrary sharedPhotoLibrary] presentLimitedLibraryPickerFromViewController:self.viewController completionHandler:^(NSArray * _Nonnull identifiers) { 169 | NSString* jsonArray = [diagnostic arrayToJsonString:identifiers]; 170 | [diagnostic sendPluginResultString:jsonArray :command]; 171 | }]; 172 | [diagnostic sendPluginNoResultAndKeepCallback:command]; 173 | } 174 | else if (@available(iOS 14.0, *)){ 175 | [[PHPhotoLibrary sharedPhotoLibrary] presentLimitedLibraryPickerFromViewController:self.viewController]; 176 | [diagnostic sendPluginResultSuccess:command]; 177 | }else{ 178 | [diagnostic sendPluginError:@"Limited photo library access UI is not supported on iOS < 14" :command]; 179 | } 180 | } 181 | @catch (NSException *exception) { 182 | [diagnostic handlePluginException:exception :command]; 183 | } 184 | }]; 185 | } 186 | 187 | 188 | /********************************/ 189 | #pragma mark - Internals 190 | /********************************/ 191 | 192 | - (BOOL) isCameraPresent 193 | { 194 | BOOL cameraAvailable = 195 | [UIImagePickerController 196 | isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]; 197 | if(cameraAvailable) { 198 | [diagnostic logDebug:@"Camera available"]; 199 | return true; 200 | } 201 | else { 202 | [diagnostic logDebug:@"Camera unavailable"]; 203 | return false; 204 | } 205 | } 206 | 207 | - (BOOL) isCameraAuthorized 208 | { 209 | AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; 210 | if(authStatus == AVAuthorizationStatusAuthorized) { 211 | return true; 212 | } else { 213 | return false; 214 | } 215 | } 216 | 217 | - (NSString*) resolveCameraRollAuthorizationStatusFromCommand: (CDVInvokedUrlCommand*)command{ 218 | return [self resolveCameraRollAuthorizationStatusFromString:[command.arguments objectAtIndex:0]]; 219 | } 220 | 221 | - (NSString*) resolveCameraRollAuthorizationStatusFromString: (NSString*)s_accessLevel{ 222 | PHAuthorizationStatus authStatus = [PHPhotoLibrary authorizationStatus]; 223 | if (@available(iOS 14.0, *)){ 224 | PHAccessLevel ph_accessLevel = [self resolveAccessLevelFromArgument:s_accessLevel]; 225 | authStatus = [PHPhotoLibrary authorizationStatusForAccessLevel:ph_accessLevel]; 226 | }else{ 227 | authStatus = [PHPhotoLibrary authorizationStatus]; 228 | } 229 | return [self getCameraRollAuthorizationStatusAsString:authStatus]; 230 | } 231 | 232 | - (NSString*) getCameraRollAuthorizationStatusAsString: (PHAuthorizationStatus)authStatus 233 | { 234 | NSString* status = UNKNOWN; 235 | if (@available(iOS 14.0, *)){ 236 | if(authStatus == PHAuthorizationStatusLimited ){ 237 | status = AUTHORIZATION_LIMITED; 238 | } 239 | } 240 | 241 | if([status isEqualToString:UNKNOWN]){ 242 | if(authStatus == PHAuthorizationStatusDenied || authStatus == PHAuthorizationStatusRestricted){ 243 | status = AUTHORIZATION_DENIED; 244 | }else if(authStatus == PHAuthorizationStatusNotDetermined ){ 245 | status = AUTHORIZATION_NOT_DETERMINED; 246 | }else if(authStatus == PHAuthorizationStatusAuthorized){ 247 | status = AUTHORIZATION_GRANTED; 248 | } 249 | } 250 | 251 | return status; 252 | } 253 | 254 | - (PHAccessLevel) resolveAccessLevelFromArgument:(NSString*) s_accessLevel API_AVAILABLE(ios(14)){ 255 | PHAccessLevel ph_accessLevel; 256 | if(![diagnostic isNull:s_accessLevel] && [s_accessLevel isEqualToString:PHOTOLIBRARY_ACCESS_LEVEL_READ_WRITE]){ 257 | ph_accessLevel = PHAccessLevelReadWrite; 258 | }else{ 259 | ph_accessLevel = PHAccessLevelAddOnly; 260 | } 261 | return ph_accessLevel; 262 | } 263 | 264 | @end 265 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Contacts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic_Contacts.h 3 | * Diagnostic Plugin - Contacts Module 4 | * 5 | * Copyright (c) 2018 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import 10 | #import 11 | #import "Diagnostic.h" 12 | 13 | #import 14 | #import 15 | 16 | @interface Diagnostic_Contacts : CDVPlugin 17 | 18 | @property (nonatomic, retain) CNContactStore* contactStore; 19 | 20 | - (void) getAddressBookAuthorizationStatus: (CDVInvokedUrlCommand*)command; 21 | - (void) isAddressBookAuthorized: (CDVInvokedUrlCommand*)command; 22 | - (void) requestAddressBookAuthorization: (CDVInvokedUrlCommand*)command; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Contacts.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic_Contacts.m 3 | * Diagnostic Plugin - Contacts Module 4 | * 5 | * Copyright (c) 2018 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import "Diagnostic_Contacts.h" 10 | 11 | @implementation Diagnostic_Contacts 12 | 13 | // Internal reference to Diagnostic singleton instance 14 | static Diagnostic* diagnostic; 15 | 16 | 17 | // Internal constants 18 | static NSString*const LOG_TAG = @"Diagnostic_Contacts[native]"; 19 | 20 | - (void)pluginInitialize { 21 | 22 | [super pluginInitialize]; 23 | 24 | diagnostic = [Diagnostic getInstance]; 25 | 26 | self.contactStore = [[CNContactStore alloc] init]; 27 | } 28 | 29 | /********************************/ 30 | #pragma mark - Plugin API 31 | /********************************/ 32 | 33 | 34 | - (void) getAddressBookAuthorizationStatus: (CDVInvokedUrlCommand*)command 35 | { 36 | [self.commandDelegate runInBackground:^{ 37 | @try { 38 | NSString* status; 39 | 40 | CNAuthorizationStatus authStatus = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]; 41 | if(authStatus == CNAuthorizationStatusDenied || authStatus == CNAuthorizationStatusRestricted){ 42 | status = AUTHORIZATION_DENIED; 43 | }else if(authStatus == CNAuthorizationStatusNotDetermined){ 44 | status = AUTHORIZATION_NOT_DETERMINED; 45 | }else if(authStatus == CNAuthorizationStatusAuthorized){ 46 | status = AUTHORIZATION_GRANTED; 47 | } 48 | 49 | [diagnostic logDebug:[NSString stringWithFormat:@"Address book authorization status is: %@", status]]; 50 | [diagnostic sendPluginResultString:status:command]; 51 | 52 | } 53 | @catch (NSException *exception) { 54 | [diagnostic handlePluginException:exception :command]; 55 | } 56 | }]; 57 | } 58 | 59 | - (void) isAddressBookAuthorized: (CDVInvokedUrlCommand*)command 60 | { 61 | [self.commandDelegate runInBackground:^{ 62 | @try { 63 | CNAuthorizationStatus authStatus = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]; 64 | [diagnostic sendPluginResultBool:authStatus == CNAuthorizationStatusAuthorized :command]; 65 | } 66 | @catch (NSException *exception) { 67 | [diagnostic handlePluginException:exception :command]; 68 | } 69 | }]; 70 | } 71 | 72 | - (void) requestAddressBookAuthorization: (CDVInvokedUrlCommand*)command 73 | { 74 | [self.commandDelegate runInBackground:^{ 75 | @try { 76 | [self.contactStore requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) { 77 | if(error == nil) { 78 | [diagnostic logDebug:[NSString stringWithFormat:@"Access request to address book: %d", granted]]; 79 | [diagnostic sendPluginResultBool:granted :command]; 80 | } 81 | else { 82 | [diagnostic sendPluginResultBool:FALSE :command]; 83 | } 84 | }]; 85 | } 86 | @catch (NSException *exception) { 87 | [diagnostic handlePluginException:exception :command]; 88 | } 89 | }]; 90 | } 91 | 92 | 93 | @end 94 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Location.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic_Location.h 3 | * Diagnostic Plugin - Location Module 4 | * 5 | * Copyright (c) 2018 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import 10 | #import 11 | #import "Diagnostic.h" 12 | #import 13 | 14 | 15 | 16 | @interface Diagnostic_Location : CDVPlugin 17 | 18 | @property (strong, nonatomic) CLLocationManager* locationManager; 19 | @property (nonatomic, retain) NSString* locationRequestCallbackId; 20 | @property (nonatomic, retain) NSString* currentLocationAuthorizationStatus; 21 | @property (nonatomic, retain) NSString* currentLocationAccuracyAuthorization; 22 | 23 | - (void) isLocationAvailable: (CDVInvokedUrlCommand*)command; 24 | - (void) isLocationEnabled: (CDVInvokedUrlCommand*)command; 25 | - (void) isLocationAuthorized: (CDVInvokedUrlCommand*)command; 26 | - (void) getLocationAuthorizationStatus: (CDVInvokedUrlCommand*)command; 27 | - (void) getLocationAccuracyAuthorization: (CDVInvokedUrlCommand*)command; 28 | - (void) requestLocationAuthorization: (CDVInvokedUrlCommand*)command; 29 | - (void) requestTemporaryFullAccuracyAuthorization: (CDVInvokedUrlCommand*)command; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Microphone.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic_Microphone.h 3 | * Diagnostic Plugin - Microphone Module 4 | * 5 | * Copyright (c) 2018 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import 10 | #import 11 | #import "Diagnostic.h" 12 | 13 | #import 14 | 15 | @interface Diagnostic_Microphone : CDVPlugin 16 | 17 | - (void) isMicrophoneAuthorized: (CDVInvokedUrlCommand*)command; 18 | - (void) getMicrophoneAuthorizationStatus: (CDVInvokedUrlCommand*)command; 19 | - (void) requestMicrophoneAuthorization: (CDVInvokedUrlCommand*)command; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Microphone.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic_Microphone.m 3 | * Diagnostic Plugin - Microphone Module 4 | * 5 | * Copyright (c) 2018 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import "Diagnostic_Microphone.h" 10 | 11 | @implementation Diagnostic_Microphone 12 | 13 | // Internal reference to Diagnostic singleton instance 14 | static Diagnostic* diagnostic; 15 | 16 | // Internal constants 17 | static NSString*const LOG_TAG = @"Diagnostic_Microphone[native]"; 18 | 19 | - (void)pluginInitialize { 20 | 21 | [super pluginInitialize]; 22 | 23 | diagnostic = [Diagnostic getInstance]; 24 | } 25 | 26 | /********************************/ 27 | #pragma mark - Plugin API 28 | /********************************/ 29 | 30 | - (void) isMicrophoneAuthorized: (CDVInvokedUrlCommand*)command 31 | { 32 | [self.commandDelegate runInBackground:^{ 33 | CDVPluginResult* pluginResult; 34 | @try { 35 | AVAudioSessionRecordPermission recordPermission = [AVAudioSession sharedInstance].recordPermission; 36 | 37 | if(recordPermission == AVAudioSessionRecordPermissionGranted) { 38 | pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:1]; 39 | } 40 | else { 41 | pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:0]; 42 | } 43 | [diagnostic sendPluginResultBool:recordPermission == AVAudioSessionRecordPermissionGranted :command]; 44 | } 45 | @catch (NSException *exception) { 46 | [diagnostic handlePluginException:exception :command]; 47 | }; 48 | }]; 49 | } 50 | 51 | - (void) getMicrophoneAuthorizationStatus: (CDVInvokedUrlCommand*)command 52 | { 53 | [self.commandDelegate runInBackground:^{ 54 | @try { 55 | NSString* status; 56 | AVAudioSessionRecordPermission recordPermission = [AVAudioSession sharedInstance].recordPermission; 57 | switch(recordPermission){ 58 | case AVAudioSessionRecordPermissionDenied: 59 | status = AUTHORIZATION_DENIED; 60 | break; 61 | case AVAudioSessionRecordPermissionGranted: 62 | status = AUTHORIZATION_GRANTED; 63 | break; 64 | case AVAudioSessionRecordPermissionUndetermined: 65 | status = AUTHORIZATION_NOT_DETERMINED; 66 | break; 67 | } 68 | 69 | [diagnostic logDebug:[NSString stringWithFormat:@"Microphone authorization status is: %@", status]]; 70 | [diagnostic sendPluginResultString:status:command]; 71 | } 72 | @catch (NSException *exception) { 73 | [diagnostic handlePluginException:exception :command]; 74 | } 75 | }]; 76 | } 77 | 78 | - (void) requestMicrophoneAuthorization: (CDVInvokedUrlCommand*)command 79 | { 80 | [self.commandDelegate runInBackground:^{ 81 | @try { 82 | [[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) { 83 | [diagnostic logDebug:[NSString stringWithFormat:@"Has access to microphone: %d", granted]]; 84 | [diagnostic sendPluginResultBool:granted :command]; 85 | }]; 86 | } 87 | @catch (NSException *exception) { 88 | [diagnostic handlePluginException:exception :command]; 89 | } 90 | }]; 91 | } 92 | 93 | /********************************/ 94 | #pragma mark - Internals 95 | /********************************/ 96 | 97 | @end 98 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Motion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic_Motion.h 3 | * Diagnostic Plugin - Motion Module 4 | * 5 | * Copyright (c) 2018 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import 10 | #import 11 | #import "Diagnostic.h" 12 | 13 | #import 14 | 15 | 16 | @interface Diagnostic_Motion : CDVPlugin 17 | 18 | @property (strong, nonatomic) CMMotionActivityManager* motionManager; 19 | @property (strong, nonatomic) NSOperationQueue* motionActivityQueue; 20 | @property (nonatomic, retain) CMPedometer* cmPedometer; 21 | 22 | - (void) isMotionAvailable: (CDVInvokedUrlCommand*)command; 23 | - (void) isMotionRequestOutcomeAvailable: (CDVInvokedUrlCommand*)command; 24 | - (void) getMotionAuthorizationStatus: (CDVInvokedUrlCommand*)command; 25 | - (void) requestMotionAuthorization: (CDVInvokedUrlCommand*)command; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Motion.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic_Motion.m 3 | * Diagnostic Plugin - Motion Module 4 | * 5 | * Copyright (c) 2018 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import "Diagnostic_Motion.h" 10 | 11 | @implementation Diagnostic_Motion 12 | 13 | // Internal reference to Diagnostic singleton instance 14 | static Diagnostic* diagnostic; 15 | 16 | // Internal constants 17 | static NSString*const LOG_TAG = @"Diagnostic_Motion[native]"; 18 | 19 | /********************************/ 20 | #pragma mark - Plugin API 21 | /********************************/ 22 | - (void) isMotionAvailable:(CDVInvokedUrlCommand *)command 23 | { 24 | [self.commandDelegate runInBackground:^{ 25 | @try { 26 | 27 | [diagnostic sendPluginResultBool:[self isMotionAvailable] :command]; 28 | } 29 | @catch (NSException *exception) { 30 | [diagnostic handlePluginException:exception :command]; 31 | } 32 | }]; 33 | } 34 | 35 | - (void) isMotionRequestOutcomeAvailable:(CDVInvokedUrlCommand *)command 36 | { 37 | [self.commandDelegate runInBackground:^{ 38 | @try { 39 | 40 | [diagnostic sendPluginResultBool:[self isMotionRequestOutcomeAvailable] :command]; 41 | } 42 | @catch (NSException *exception) { 43 | [diagnostic handlePluginException:exception :command]; 44 | } 45 | }]; 46 | } 47 | 48 | - (void) getMotionAuthorizationStatus: (CDVInvokedUrlCommand*)command 49 | { 50 | [self.commandDelegate runInBackground:^{ 51 | if(![self isMotionAvailable]){ 52 | // Activity tracking not available on this device 53 | [diagnostic sendPluginResultString:@"not_available":command]; 54 | }else if([diagnostic getSetting:@"motion_permission_requested"] == nil){ 55 | // Permission not yet requested 56 | [diagnostic sendPluginResultString:@"not_requested":command]; 57 | }else{ 58 | // Permission has been requested so determine the outcome 59 | [self _requestMotionAuthorization:command]; 60 | } 61 | }]; 62 | } 63 | 64 | - (void) requestMotionAuthorization: (CDVInvokedUrlCommand*)command{ 65 | [self.commandDelegate runInBackground:^{ 66 | if([diagnostic getSetting:@"motion_permission_requested"] != nil){ 67 | [diagnostic sendPluginError:@"requestMotionAuthorization() has already been called and can only be called once after app installation":command]; 68 | }else{ 69 | [self _requestMotionAuthorization:command]; 70 | } 71 | }]; 72 | } 73 | 74 | 75 | /********************************/ 76 | #pragma mark - Internals 77 | /********************************/ 78 | 79 | - (void)pluginInitialize { 80 | 81 | [super pluginInitialize]; 82 | 83 | diagnostic = [Diagnostic getInstance]; 84 | 85 | self.motionManager = [[CMMotionActivityManager alloc] init]; 86 | self.motionActivityQueue = [[NSOperationQueue alloc] init]; 87 | self.cmPedometer = [[CMPedometer alloc] init]; 88 | } 89 | 90 | - (void) _requestMotionAuthorization: (CDVInvokedUrlCommand*)command 91 | { 92 | @try { 93 | if([self isMotionAvailable]){ 94 | @try { 95 | [self.cmPedometer queryPedometerDataFromDate:[NSDate date] 96 | toDate:[NSDate date] 97 | withHandler:^(CMPedometerData* data, NSError *error) { 98 | @try { 99 | [diagnostic setSetting:@"motion_permission_requested" forValue:(id)kCFBooleanTrue]; 100 | NSString* status = UNKNOWN; 101 | if (error != nil) { 102 | if (error.code == CMErrorMotionActivityNotAuthorized) { 103 | status = AUTHORIZATION_DENIED; 104 | }else if (error.code == CMErrorMotionActivityNotEntitled) { 105 | status = @"restricted"; 106 | }else if (error.code == CMErrorMotionActivityNotAvailable) { 107 | // Motion request outcome cannot be determined on this device 108 | status = AUTHORIZATION_NOT_DETERMINED; 109 | } 110 | } 111 | else{ 112 | status = AUTHORIZATION_GRANTED; 113 | } 114 | 115 | [diagnostic logDebug:[NSString stringWithFormat:@"Motion tracking authorization status is %@", status]]; 116 | [diagnostic sendPluginResultString:status:command]; 117 | }@catch (NSException *exception) { 118 | [diagnostic handlePluginException:exception :command]; 119 | } 120 | }]; 121 | }@catch (NSException *exception) { 122 | [diagnostic handlePluginException:exception :command]; 123 | } 124 | }else{ 125 | // Activity tracking not available on this device 126 | [diagnostic sendPluginResultString:@"not_available":command]; 127 | } 128 | }@catch (NSException *exception) { 129 | [diagnostic handlePluginException:exception :command]; 130 | } 131 | } 132 | 133 | - (BOOL) isMotionAvailable 134 | { 135 | return [CMMotionActivityManager isActivityAvailable]; 136 | } 137 | 138 | - (BOOL) isMotionRequestOutcomeAvailable 139 | { 140 | return [CMPedometer respondsToSelector:@selector(isPedometerEventTrackingAvailable)] && [CMPedometer isPedometerEventTrackingAvailable]; 141 | } 142 | 143 | @end 144 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Notifications.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic_Notifications.h 3 | * Diagnostic Plugin - Notifications Module 4 | * 5 | * Copyright (c) 2018 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import 10 | #import 11 | #import "Diagnostic.h" 12 | #import 13 | 14 | @interface Diagnostic_Notifications : CDVPlugin 15 | 16 | - (void) isRemoteNotificationsEnabled: (CDVInvokedUrlCommand*)command; 17 | - (void) getRemoteNotificationTypes: (CDVInvokedUrlCommand*)command; 18 | - (void) isRegisteredForRemoteNotifications: (CDVInvokedUrlCommand*)command; 19 | - (void) getRemoteNotificationsAuthorizationStatus: (CDVInvokedUrlCommand*)command; 20 | - (void) requestRemoteNotificationsAuthorization: (CDVInvokedUrlCommand*)command; 21 | - (void) switchToNotificationSettings: (CDVInvokedUrlCommand*)command; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Notifications.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic_Notifications.m 3 | * Diagnostic Plugin - Notifications Module 4 | * 5 | * Copyright (c) 2018 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import "Diagnostic_Notifications.h" 10 | 11 | @implementation Diagnostic_Notifications 12 | 13 | // Internal reference to Diagnostic singleton instance 14 | static Diagnostic* diagnostic; 15 | 16 | // Internal constants 17 | static NSString*const LOG_TAG = @"Diagnostic_Notifications[native]"; 18 | 19 | static NSString*const REMOTE_NOTIFICATIONS_ALERT = @"alert"; 20 | static NSString*const REMOTE_NOTIFICATIONS_SOUND = @"sound"; 21 | static NSString*const REMOTE_NOTIFICATIONS_BADGE = @"badge"; 22 | 23 | - (void)pluginInitialize { 24 | 25 | [super pluginInitialize]; 26 | 27 | diagnostic = [Diagnostic getInstance]; 28 | } 29 | 30 | /********************************/ 31 | #pragma mark - Plugin API 32 | /********************************/ 33 | 34 | - (void) isRemoteNotificationsEnabled: (CDVInvokedUrlCommand*)command 35 | { 36 | [self.commandDelegate runInBackground:^{ 37 | @try { 38 | UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; 39 | [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) { 40 | BOOL userSettingEnabled = settings.authorizationStatus == UNAuthorizationStatusAuthorized; 41 | [self isRemoteNotificationsEnabledResult:userSettingEnabled:command]; 42 | }]; 43 | } 44 | @catch (NSException *exception) { 45 | [diagnostic handlePluginException:exception:command]; 46 | } 47 | }]; 48 | } 49 | - (void) isRemoteNotificationsEnabledResult: (BOOL) userSettingEnabled : (CDVInvokedUrlCommand*)command 50 | { 51 | [self _isRegisteredForRemoteNotifications:^(BOOL remoteNotificationsEnabled) { 52 | BOOL isEnabled = remoteNotificationsEnabled && userSettingEnabled; 53 | [diagnostic sendPluginResultBool:isEnabled:command]; 54 | }]; 55 | } 56 | 57 | - (void) getRemoteNotificationTypes: (CDVInvokedUrlCommand*)command 58 | { 59 | [self.commandDelegate runInBackground:^{ 60 | @try { 61 | UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; 62 | [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) { 63 | BOOL alertsEnabled = settings.alertSetting == UNNotificationSettingEnabled; 64 | BOOL badgesEnabled = settings.badgeSetting == UNNotificationSettingEnabled; 65 | BOOL soundsEnabled = settings.soundSetting == UNNotificationSettingEnabled; 66 | BOOL noneEnabled = !alertsEnabled && !badgesEnabled && !soundsEnabled; 67 | [self getRemoteNotificationTypesResult:command:noneEnabled:alertsEnabled:badgesEnabled:soundsEnabled]; 68 | }]; 69 | } 70 | @catch (NSException *exception) { 71 | [diagnostic handlePluginException:exception :command]; 72 | } 73 | }]; 74 | } 75 | - (void) getRemoteNotificationTypesResult: (CDVInvokedUrlCommand*)command :(BOOL)noneEnabled :(BOOL)alertsEnabled :(BOOL)badgesEnabled :(BOOL)soundsEnabled 76 | { 77 | NSMutableDictionary* types = [[NSMutableDictionary alloc]init]; 78 | if(alertsEnabled) { 79 | [types setValue:@"1" forKey:REMOTE_NOTIFICATIONS_ALERT]; 80 | } else { 81 | [types setValue:@"0" forKey:REMOTE_NOTIFICATIONS_ALERT]; 82 | } 83 | if(badgesEnabled) { 84 | [types setValue:@"1" forKey:REMOTE_NOTIFICATIONS_BADGE]; 85 | } else { 86 | [types setValue:@"0" forKey:REMOTE_NOTIFICATIONS_BADGE]; 87 | } 88 | if(soundsEnabled) { 89 | [types setValue:@"1" forKey:REMOTE_NOTIFICATIONS_SOUND]; 90 | } else {; 91 | [types setValue:@"0" forKey:REMOTE_NOTIFICATIONS_SOUND]; 92 | } 93 | [diagnostic sendPluginResultString:[diagnostic objectToJsonString:types]:command]; 94 | } 95 | 96 | 97 | - (void) isRegisteredForRemoteNotifications: (CDVInvokedUrlCommand*)command 98 | { 99 | [self.commandDelegate runInBackground:^{ 100 | @try { 101 | [self _isRegisteredForRemoteNotifications:^(BOOL registered) { 102 | [diagnostic sendPluginResultBool:registered :command]; 103 | }]; 104 | } 105 | @catch (NSException *exception) { 106 | [diagnostic handlePluginException:exception :command]; 107 | } 108 | }]; 109 | } 110 | 111 | - (void) getRemoteNotificationsAuthorizationStatus: (CDVInvokedUrlCommand*)command 112 | { 113 | [self.commandDelegate runInBackground:^{ 114 | @try { 115 | UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; 116 | [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) { 117 | NSString* status = UNKNOWN; 118 | UNAuthorizationStatus authStatus = settings.authorizationStatus; 119 | if(authStatus == UNAuthorizationStatusDenied){ 120 | status = AUTHORIZATION_DENIED; 121 | }else if(authStatus == UNAuthorizationStatusNotDetermined){ 122 | status = AUTHORIZATION_NOT_DETERMINED; 123 | }else if(authStatus == UNAuthorizationStatusAuthorized){ 124 | status = AUTHORIZATION_GRANTED; 125 | }else if(@available(iOS 12.0, *)) { 126 | if(authStatus == UNAuthorizationStatusProvisional) { 127 | status = AUTHORIZATION_PROVISIONAL; 128 | } 129 | }else if (@available(iOS 14.0, *)) { 130 | if(authStatus == UNAuthorizationStatusEphemeral) { 131 | status = AUTHORIZATION_EPHEMERAL; 132 | } 133 | } 134 | [diagnostic logDebug:[NSString stringWithFormat:@"Remote notifications authorization status is: %@", status]]; 135 | [diagnostic sendPluginResultString:status:command]; 136 | }]; 137 | } 138 | @catch (NSException *exception) { 139 | [diagnostic handlePluginException:exception:command]; 140 | } 141 | }]; 142 | } 143 | 144 | - (void) requestRemoteNotificationsAuthorization: (CDVInvokedUrlCommand*)command 145 | { 146 | [self.commandDelegate runInBackground:^{ 147 | @try { 148 | NSString* s_options = [command.arguments objectAtIndex:0]; 149 | if([diagnostic isNull:s_options]){ 150 | NSArray* a_options = [NSArray arrayWithObjects:REMOTE_NOTIFICATIONS_ALERT, REMOTE_NOTIFICATIONS_SOUND, REMOTE_NOTIFICATIONS_BADGE, nil]; 151 | s_options = [diagnostic arrayToJsonString:a_options]; 152 | } 153 | NSDictionary* d_options = [diagnostic jsonStringToDictionary:s_options]; 154 | 155 | BOOL omitRegistration = [[command argumentAtIndex:1] boolValue]; 156 | UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; 157 | 158 | [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) { 159 | UNAuthorizationStatus authStatus = settings.authorizationStatus; 160 | BOOL shouldAskForAuthorization = FALSE; 161 | 162 | if (authStatus == UNAuthorizationStatusNotDetermined) { 163 | shouldAskForAuthorization = TRUE; 164 | } else if(@available(iOS 12,*)) { 165 | if(authStatus == UNAuthorizationStatusProvisional) { 166 | shouldAskForAuthorization = TRUE; 167 | } 168 | } else if(@available(iOS 14,*)) { 169 | if(authStatus == UNAuthorizationStatusEphemeral) { 170 | shouldAskForAuthorization = TRUE; 171 | } 172 | } 173 | 174 | if(shouldAskForAuthorization){ 175 | UNAuthorizationOptions options = UNAuthorizationOptionNone; 176 | for(id key in d_options){ 177 | NSString* s_key = (NSString*) key; 178 | if([s_key isEqualToString:REMOTE_NOTIFICATIONS_ALERT]){ 179 | options = options + UNAuthorizationOptionAlert; 180 | }else if([s_key isEqualToString:REMOTE_NOTIFICATIONS_SOUND]){ 181 | options = options + UNAuthorizationOptionSound; 182 | }else if([s_key isEqualToString:REMOTE_NOTIFICATIONS_BADGE]){ 183 | options = options + UNAuthorizationOptionBadge; 184 | } 185 | } 186 | 187 | [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:options completionHandler:^(BOOL granted, NSError * _Nullable error) { 188 | if(error != nil){ 189 | [diagnostic sendPluginError:[NSString stringWithFormat:@"Error when requesting remote notifications authorization: %@", error] :command]; 190 | }else if (granted) { 191 | [diagnostic logDebug:@"Remote notifications authorization granted"]; 192 | if(!omitRegistration){ 193 | dispatch_async(dispatch_get_main_queue(), ^{ 194 | [[UIApplication sharedApplication] registerForRemoteNotifications]; 195 | [diagnostic sendPluginResultString:AUTHORIZATION_GRANTED:command]; 196 | }); 197 | }else{ 198 | [diagnostic sendPluginResultString:AUTHORIZATION_GRANTED:command]; 199 | } 200 | }else{ 201 | [diagnostic sendPluginError:@"Remote notifications authorization was denied" :command]; 202 | } 203 | }]; 204 | }else if(authStatus == UNAuthorizationStatusAuthorized){ 205 | [diagnostic logDebug:@"Remote notifications already authorized"]; 206 | if(!omitRegistration){ 207 | dispatch_async(dispatch_get_main_queue(), ^{ 208 | [[UIApplication sharedApplication] registerForRemoteNotifications]; 209 | [diagnostic sendPluginResultString:AUTHORIZATION_GRANTED:command]; 210 | }); 211 | }else{ 212 | [diagnostic sendPluginResultString:AUTHORIZATION_GRANTED:command]; 213 | } 214 | [diagnostic sendPluginResultString:@"already_authorized":command]; 215 | }else if(authStatus == UNAuthorizationStatusDenied){ 216 | [diagnostic sendPluginError:@"Remote notifications authorization is denied" :command]; 217 | } 218 | }]; 219 | } 220 | @catch (NSException *exception) { 221 | [diagnostic handlePluginException:exception:command]; 222 | } 223 | }]; 224 | } 225 | 226 | - (void) switchToNotificationSettings: (CDVInvokedUrlCommand*)command 227 | { 228 | @try { 229 | if (@available(iOS 15.4, *)) { 230 | [[UIApplication sharedApplication] openURL:[NSURL URLWithString: UIApplicationOpenNotificationSettingsURLString] options:@{} completionHandler:^(BOOL success) { 231 | if (success) { 232 | [diagnostic sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] :command]; 233 | }else{ 234 | [diagnostic sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR] :command]; 235 | } 236 | }]; 237 | } else { 238 | [[UIApplication sharedApplication] openURL:[NSURL URLWithString: UIApplicationOpenSettingsURLString] options:@{} completionHandler:^(BOOL success) { 239 | if (success) { 240 | [diagnostic sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] :command]; 241 | }else{ 242 | [diagnostic sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR] :command]; 243 | } 244 | }]; 245 | } 246 | } 247 | @catch (NSException *exception) { 248 | [diagnostic handlePluginException:exception :command]; 249 | } 250 | } 251 | 252 | - (void) _isRegisteredForRemoteNotifications:(void (^)(BOOL result))completeBlock { 253 | dispatch_async(dispatch_get_main_queue(), ^{ 254 | BOOL registered = [UIApplication sharedApplication].isRegisteredForRemoteNotifications; 255 | if( completeBlock ){ 256 | completeBlock(registered); 257 | } 258 | }); 259 | }; 260 | 261 | @end 262 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Reminders.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic_Reminders.h 3 | * Diagnostic Plugin - Reminders Module 4 | * 5 | * Copyright (c) 2018 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import 10 | #import 11 | #import "Diagnostic.h" 12 | 13 | #import 14 | 15 | 16 | @interface Diagnostic_Reminders : CDVPlugin 17 | 18 | @property (nonatomic) EKEventStore *eventStore; 19 | 20 | - (void) getRemindersAuthorizationStatus: (CDVInvokedUrlCommand*)command; 21 | - (void) isRemindersAuthorized: (CDVInvokedUrlCommand*)command; 22 | - (void) requestRemindersAuthorization: (CDVInvokedUrlCommand*)command; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Reminders.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic_Reminders.m 3 | * Diagnostic Plugin - Reminders Module 4 | * 5 | * Copyright (c) 2018 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import "Diagnostic_Reminders.h" 10 | 11 | @implementation Diagnostic_Reminders 12 | 13 | // Internal reference to Diagnostic singleton instance 14 | static Diagnostic* diagnostic; 15 | 16 | // Internal constants 17 | static NSString*const LOG_TAG = @"Diagnostic_Reminders[native]"; 18 | 19 | - (void)pluginInitialize { 20 | 21 | [super pluginInitialize]; 22 | 23 | diagnostic = [Diagnostic getInstance]; 24 | 25 | } 26 | 27 | /********************************/ 28 | #pragma mark - Plugin API 29 | /********************************/ 30 | 31 | - (void) getRemindersAuthorizationStatus: (CDVInvokedUrlCommand*)command 32 | { 33 | [self.commandDelegate runInBackground:^{ 34 | @try { 35 | NSString* status; 36 | 37 | EKAuthorizationStatus authStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeReminder]; 38 | 39 | if(authStatus == EKAuthorizationStatusDenied || authStatus == EKAuthorizationStatusRestricted){ 40 | status = AUTHORIZATION_DENIED; 41 | }else if(authStatus == EKAuthorizationStatusNotDetermined){ 42 | status = AUTHORIZATION_NOT_DETERMINED; 43 | }else if(authStatus == EKAuthorizationStatusAuthorized){ 44 | status = AUTHORIZATION_GRANTED; 45 | } 46 | [diagnostic logDebug:[NSString stringWithFormat:@"Reminders authorization status is: %@", status]]; 47 | [diagnostic sendPluginResultString:status:command]; 48 | } 49 | @catch (NSException *exception) { 50 | [diagnostic handlePluginException:exception :command]; 51 | } 52 | }]; 53 | } 54 | 55 | - (void) isRemindersAuthorized: (CDVInvokedUrlCommand*)command 56 | { 57 | [self.commandDelegate runInBackground:^{ 58 | @try { 59 | EKAuthorizationStatus authStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeReminder]; 60 | [diagnostic sendPluginResultBool:authStatus == EKAuthorizationStatusAuthorized:command]; 61 | } 62 | @catch (NSException *exception) { 63 | [diagnostic handlePluginException:exception :command]; 64 | } 65 | }]; 66 | } 67 | 68 | - (void) requestRemindersAuthorization: (CDVInvokedUrlCommand*)command 69 | { 70 | [self.commandDelegate runInBackground:^{ 71 | @try { 72 | 73 | if (!self.eventStore) { 74 | self.eventStore = [EKEventStore new]; 75 | } 76 | 77 | [self.eventStore requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) { 78 | [diagnostic logDebug:[NSString stringWithFormat:@"Access request to reminders: %d", granted]]; 79 | [diagnostic sendPluginResultBool:granted:command]; 80 | }]; 81 | } 82 | @catch (NSException *exception) { 83 | [diagnostic handlePluginException:exception :command]; 84 | } 85 | }]; 86 | } 87 | 88 | /********************************/ 89 | #pragma mark - Internals 90 | /********************************/ 91 | 92 | 93 | @end 94 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Resources.bundle/PrivacyInfo.xcprivacy: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSPrivacyTracking 6 | 7 | NSPrivacyTrackingDomains 8 | 9 | 10 | NSPrivacyCollectedDataTypes 11 | 12 | NSPrivacyAccessedAPITypes 13 | 14 | 15 | NSPrivacyAccessedAPIType 16 | NSPrivacyAccessedAPICategoryUserDefaults 17 | NSPrivacyAccessedAPITypeReasons 18 | 19 | CA92.1 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Wifi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic_Wifi.h 3 | * Diagnostic Plugin - Wifi Module 4 | * 5 | * Copyright (c) 2018 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import 10 | #import 11 | #import "Diagnostic.h" 12 | 13 | 14 | @interface Diagnostic_Wifi : CDVPlugin 15 | 16 | - (void) isWifiAvailable: (CDVInvokedUrlCommand*)command; 17 | - (void) isWifiEnabled: (CDVInvokedUrlCommand*)command; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /src/ios/Diagnostic_Wifi.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagnostic_Wifi.m 3 | * Diagnostic Plugin - Wifi Module 4 | * 5 | * Copyright (c) 2018 Working Edge Ltd. 6 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 7 | */ 8 | 9 | #import "Diagnostic_Wifi.h" 10 | 11 | #import // For AF_INET, etc. 12 | #import // For getifaddrs() 13 | #import // For IFF_LOOPBACK 14 | 15 | @implementation Diagnostic_Wifi 16 | 17 | // Internal reference to Diagnostic singleton instance 18 | static Diagnostic* diagnostic; 19 | 20 | // Internal constants 21 | static NSString*const LOG_TAG = @"Diagnostic_Wifi[native]"; 22 | 23 | - (void)pluginInitialize { 24 | 25 | [super pluginInitialize]; 26 | 27 | diagnostic = [Diagnostic getInstance]; 28 | } 29 | 30 | /********************************/ 31 | #pragma mark - Plugin API 32 | /********************************/ 33 | 34 | - (void) isWifiAvailable: (CDVInvokedUrlCommand*)command 35 | { 36 | [self.commandDelegate runInBackground:^{ 37 | @try { 38 | [diagnostic sendPluginResultBool:[self connectedToWifi] :command]; 39 | } 40 | @catch (NSException *exception) { 41 | [diagnostic handlePluginException:exception :command]; 42 | } 43 | }]; 44 | } 45 | 46 | - (void) isWifiEnabled: (CDVInvokedUrlCommand*)command 47 | { 48 | [self.commandDelegate runInBackground:^{ 49 | @try { 50 | [diagnostic sendPluginResultBool:[self isWifiEnabled] :command]; 51 | } 52 | @catch (NSException *exception) { 53 | [diagnostic handlePluginException:exception :command]; 54 | } 55 | }]; 56 | } 57 | 58 | /********************************/ 59 | #pragma mark - Internals 60 | /********************************/ 61 | 62 | - (BOOL) isWifiEnabled { 63 | 64 | NSCountedSet * cset = [NSCountedSet new]; 65 | 66 | struct ifaddrs *interfaces; 67 | 68 | if( ! getifaddrs(&interfaces) ) { 69 | for( struct ifaddrs *interface = interfaces; interface; interface = interface->ifa_next) { 70 | if ( (interface->ifa_flags & IFF_UP) == IFF_UP ) { 71 | [cset addObject:[NSString stringWithUTF8String:interface->ifa_name]]; 72 | } 73 | } 74 | } 75 | 76 | return [cset countForObject:@"awdl0"] > 1 ? YES : NO; 77 | } 78 | 79 | - (BOOL) connectedToWifi // Don't work on iOS Simulator, only in the device 80 | { 81 | struct ifaddrs *addresses; 82 | struct ifaddrs *cursor; 83 | BOOL wiFiAvailable = NO; 84 | 85 | if (getifaddrs(&addresses) != 0) { 86 | return NO; 87 | } 88 | 89 | cursor = addresses; 90 | while (cursor != NULL) { 91 | if (cursor -> ifa_addr -> sa_family == AF_INET && !(cursor -> ifa_flags & IFF_LOOPBACK)) // Ignore the loopback address 92 | { 93 | // Check for WiFi adapter 94 | if (strcmp(cursor -> ifa_name, "en0") == 0) { 95 | 96 | [diagnostic logDebug:@"Wifi ON"]; 97 | wiFiAvailable = YES; 98 | break; 99 | } 100 | } 101 | cursor = cursor -> ifa_next; 102 | } 103 | freeifaddrs(addresses); 104 | return wiFiAvailable; 105 | } 106 | 107 | 108 | @end 109 | -------------------------------------------------------------------------------- /www/android/diagnostic.calendar.js: -------------------------------------------------------------------------------- 1 | /* globals cordova, require, exports, module */ 2 | 3 | /** 4 | * Diagnostic Calendar plugin for Android 5 | * 6 | * Copyright (c) 2015 Working Edge Ltd. 7 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 8 | **/ 9 | var Diagnostic_Calendar = (function(){ 10 | /*********************** 11 | * 12 | * Internal properties 13 | * 14 | *********************/ 15 | var Diagnostic_Calendar = {}; 16 | 17 | var Diagnostic = require("cordova.plugins.diagnostic.Diagnostic"); 18 | 19 | /******************** 20 | * 21 | * Public properties 22 | * 23 | ********************/ 24 | 25 | /******************** 26 | * 27 | * Internal functions 28 | * 29 | ********************/ 30 | 31 | 32 | /***************************** 33 | * 34 | * Protected member functions 35 | * 36 | ****************************/ 37 | 38 | /********************** 39 | * 40 | * Public API functions 41 | * 42 | **********************/ 43 | 44 | /** 45 | *Checks if the application is authorized to use calendar. 46 | * 47 | * @param {Function} successCallback - The callback which will be called when operation is successful. 48 | * This callback function is passed a single boolean parameter which is TRUE if access to microphone is authorized. 49 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 50 | * This callback function is passed a single string parameter containing the error message. 51 | */ 52 | Diagnostic_Calendar.isCalendarAuthorized = function(successCallback, errorCallback) { 53 | function onSuccess(status){ 54 | successCallback(status === Diagnostic.permissionStatus.GRANTED); 55 | } 56 | Diagnostic_Calendar.getCalendarAuthorizationStatus(onSuccess, errorCallback); 57 | }; 58 | 59 | /** 60 | * Returns the calendar authorization status for the application. 61 | * 62 | * @param {Function} successCallback - The callback which will be called when operation is successful. 63 | * This callback function is passed a single string parameter which indicates the authorization status. 64 | * Possible values are: 65 | * `cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED` 66 | * `cordova.plugins.diagnostic.permissionStatus.DENIED_ONCE` 67 | * `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS` 68 | * `cordova.plugins.diagnostic.permissionStatus.GRANTED` 69 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 70 | * This callback function is passed a single string parameter containing the error message. 71 | */ 72 | Diagnostic_Calendar.getCalendarAuthorizationStatus = function(successCallback, errorCallback) { 73 | Diagnostic.getPermissionAuthorizationStatus(successCallback, errorCallback, Diagnostic.permission.READ_CALENDAR); 74 | }; 75 | 76 | /** 77 | * Requests calendar authorization for the application. 78 | * Should only be called if authorization status is NOT_REQUESTED. Calling it when in any other state will have no effect. 79 | * 80 | * @param {Function} successCallback - The callback which will be called when authorization request is successful. 81 | * @param {Function} errorCallback - The callback which will be called when an error occurs. 82 | * This callback function is passed a single string parameter containing the error message. 83 | */ 84 | Diagnostic_Calendar.requestCalendarAuthorization = function(successCallback, errorCallback) { 85 | Diagnostic.requestRuntimePermission(successCallback, errorCallback, Diagnostic.permission.READ_CALENDAR); 86 | }; 87 | 88 | return Diagnostic_Calendar; 89 | }); 90 | module.exports = new Diagnostic_Calendar(); 91 | -------------------------------------------------------------------------------- /www/android/diagnostic.camera.js: -------------------------------------------------------------------------------- 1 | /* globals cordova, require, exports, module */ 2 | 3 | /** 4 | * Diagnostic Camera plugin for Android 5 | * 6 | * Copyright (c) 2015 Working Edge Ltd. 7 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 8 | **/ 9 | var Diagnostic_Camera = (function(){ 10 | /*********************** 11 | * 12 | * Internal properties 13 | * 14 | *********************/ 15 | var Diagnostic_Camera = {}; 16 | 17 | var Diagnostic = require("cordova.plugins.diagnostic.Diagnostic"); 18 | 19 | /******************** 20 | * 21 | * Public properties 22 | * 23 | ********************/ 24 | 25 | /******************** 26 | * 27 | * Internal functions 28 | * 29 | ********************/ 30 | 31 | function mapFromLegacyCameraApi() { 32 | var params; 33 | if (typeof arguments[0] === "function") { 34 | params = (arguments.length > 2 && typeof arguments[2] === "object") ? arguments[2] : {}; 35 | params.successCallback = arguments[0]; 36 | if(arguments.length > 1 && typeof arguments[1] === "function") { 37 | params.errorCallback = arguments[1]; 38 | } 39 | if(arguments.length > 2 && arguments[2] === false) { 40 | params.storage = arguments[2]; 41 | } 42 | }else { // if (typeof arguments[0] === "object") 43 | params = arguments[0]; 44 | } 45 | if(typeof params.storage === 'undefined') params.storage = true; // default to true 46 | return params; 47 | } 48 | 49 | function numberOfKeys(obj){ 50 | var count = 0; 51 | for(var k in obj){ 52 | count++; 53 | } 54 | return count; 55 | } 56 | 57 | 58 | /***************************** 59 | * 60 | * Protected member functions 61 | * 62 | ****************************/ 63 | 64 | /********************** 65 | * 66 | * Public API functions 67 | * 68 | **********************/ 69 | 70 | /** 71 | * Checks if camera is usable: both present and authorised for use. 72 | * 73 | * @param {Object} params - (optional) parameters: 74 | * - {Function} successCallback - The callback which will be called when the operation is successful. 75 | * This callback function is passed a single boolean parameter which is TRUE if camera is present and authorized for use. 76 | * - {Function} errorCallback - The callback which will be called when the operation encounters an error. 77 | * This callback function is passed a single string parameter containing the error message. 78 | * - {Boolean} storage - (Android only) If true, requests storage permissions in addition to CAMERA run-time permission. 79 | * On Android 13+, storage permissions are READ_MEDIA_IMAGES and READ_MEDIA_VIDEO. On Android 9-12, storage permission is READ_EXTERNAL_STORAGE. 80 | * cordova-plugin-camera requires both storage and camera permissions. 81 | * Defaults to true. 82 | */ 83 | Diagnostic_Camera.isCameraAvailable = function(params) { 84 | params = mapFromLegacyCameraApi.apply(this, arguments); 85 | 86 | params.successCallback = params.successCallback || function(){}; 87 | Diagnostic_Camera.isCameraPresent(function(isPresent){ 88 | if(isPresent){ 89 | Diagnostic_Camera.isCameraAuthorized(params); 90 | }else{ 91 | params.successCallback(!!isPresent); 92 | } 93 | },params.errorCallback); 94 | }; 95 | 96 | /** 97 | * Checks if camera hardware is present on device. 98 | * 99 | * @param {Function} successCallback - The callback which will be called when the operation is successful. 100 | * This callback function is passed a single boolean parameter which is TRUE if camera is present 101 | * @param {Function} errorCallback - The callback which will be called when the operation encounters an error. 102 | * This callback function is passed a single string parameter containing the error message. 103 | */ 104 | Diagnostic_Camera.isCameraPresent = function(successCallback, errorCallback) { 105 | return cordova.exec(Diagnostic._ensureBoolean(successCallback), 106 | errorCallback, 107 | 'Diagnostic_Camera', 108 | 'isCameraPresent', 109 | []); 110 | }; 111 | 112 | /** 113 | * Requests authorisation for runtime permissions to use the camera. 114 | * Note: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will have no effect as the permissions are already granted at installation time. 115 | * @param {Object} params - (optional) parameters: 116 | * - {Function} successCallback - function to call on successful request for runtime permissions. 117 | * This callback function is passed a single string parameter which defines the resulting authorisation status as a value in cordova.plugins.diagnostic.permissionStatus. 118 | * - {Function} errorCallback - function to call on failure to request authorisation. 119 | * - {Boolean} storage - (Android only) If true, requests storage permissions in addition to CAMERA run-time permission. 120 | * On Android 13+, storage permissions are READ_MEDIA_IMAGES and READ_MEDIA_VIDEO. On Android 9-12, storage permission is READ_EXTERNAL_STORAGE. 121 | * cordova-plugin-camera requires both storage and camera permissions. 122 | * Defaults to true. 123 | */ 124 | Diagnostic_Camera.requestCameraAuthorization = function(params){ 125 | params = mapFromLegacyCameraApi.apply(this, arguments); 126 | 127 | params.successCallback = params.successCallback || function(){}; 128 | var onSuccess = function(statuses){ 129 | params.successCallback(numberOfKeys(statuses) > 1 ? cordova.plugins.diagnostic._combinePermissionStatuses(statuses): statuses[Diagnostic.permission.CAMERA]); 130 | }; 131 | 132 | return cordova.exec(onSuccess, 133 | params.errorCallback, 134 | 'Diagnostic_Camera', 135 | 'requestCameraAuthorization', 136 | [!!params.storage]); 137 | }; 138 | 139 | /** 140 | * Returns the combined authorisation status for runtime permissions to use the camera. 141 | * Note: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return GRANTED status as permissions are already granted at installation time. 142 | * @param {Object} params - (optional) parameters: 143 | * - {Function} successCallback - function to call on successful request for runtime permission status. 144 | * This callback function is passed a single string parameter which defines the current authorisation status as a value in cordova.plugins.diagnostic.permissionStatus. 145 | * - {Function} errorCallback - function to call on failure to request authorisation status. 146 | * - {Boolean} storage - (Android only) If true, queries storage permissions in addition to CAMERA run-time permission. 147 | * On Android 13+, storage permissions are READ_MEDIA_IMAGES and READ_MEDIA_VIDEO. On Android 9-12, storage permission is READ_EXTERNAL_STORAGE. 148 | * cordova-plugin-camera requires both storage and camera permissions. 149 | * Defaults to true. 150 | */ 151 | Diagnostic_Camera.getCameraAuthorizationStatus = function(params){ 152 | params = mapFromLegacyCameraApi.apply(this, arguments); 153 | 154 | params.successCallback = params.successCallback || function(){}; 155 | 156 | return cordova.exec(params.successCallback, 157 | params.errorCallback, 158 | 'Diagnostic_Camera', 159 | 'getCameraAuthorizationStatus', 160 | [!!params.storage]); 161 | }; 162 | 163 | /** 164 | * Returns the individual authorisation statuses for runtime permissions to use the camera. 165 | * Note: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return GRANTED status as permissions are already granted at installation time. 166 | * @param {Object} params - (optional) parameters: 167 | * - {Function} successCallback - function to call on successful request for runtime permission status. 168 | * This callback function is passed a single object parameter where each key indicates the permission name and the value defines the current authorisation status as a value in cordova.plugins.diagnostic.permissionStatus. 169 | * - {Function} errorCallback - function to call on failure to request authorisation status. 170 | * - {Boolean} storage - (Android only) If true, queries storage permissions in addition to CAMERA run-time permission. 171 | * On Android 13+, storage permissions are READ_MEDIA_IMAGES and READ_MEDIA_VIDEO. On Android 9-12, storage permission is READ_EXTERNAL_STORAGE. 172 | * cordova-plugin-camera requires both storage and camera permissions. 173 | * Defaults to true. 174 | */ 175 | Diagnostic_Camera.getCameraAuthorizationStatuses = function(params){ 176 | params = mapFromLegacyCameraApi.apply(this, arguments); 177 | 178 | return cordova.exec(params.successCallback, 179 | params.errorCallback, 180 | 'Diagnostic_Camera', 181 | 'getCameraAuthorizationStatuses', 182 | [!!params.storage]); 183 | }; 184 | 185 | /** 186 | * Checks if the application is authorized to use the camera. 187 | * Note: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return TRUE as permissions are already granted at installation time. 188 | * @param {Object} params - (optional) parameters: 189 | * - {Function} successCallback - function to call on successful request for runtime permissions status. 190 | * This callback function is passed a single boolean parameter which is TRUE if the app currently has runtime authorisation to use location. 191 | * - {Function} errorCallback - function to call on failure to request authorisation status. 192 | * - {Boolean} storage - (Android only) If true, requests storage permissions in addition to CAMERA run-time permission. 193 | * On Android 13+, storage permissions are READ_MEDIA_IMAGES and READ_MEDIA_VIDEO. On Android 9-12, storage permission is READ_EXTERNAL_STORAGE. 194 | * cordova-plugin-camera requires both storage and camera permissions. 195 | * Defaults to true. 196 | */ 197 | Diagnostic_Camera.isCameraAuthorized = function(params){ 198 | params = mapFromLegacyCameraApi.apply(this, arguments); 199 | 200 | params.successCallback = params.successCallback || function(){}; 201 | var onSuccess = function(status){ 202 | params.successCallback(status === Diagnostic.permissionStatus.GRANTED || status === Diagnostic.permissionStatus.LIMITED); 203 | }; 204 | 205 | Diagnostic_Camera.getCameraAuthorizationStatus({ 206 | successCallback: onSuccess, 207 | errorCallback: params.errorCallback, 208 | storage: params.storage 209 | }); 210 | }; 211 | 212 | return Diagnostic_Camera; 213 | }); 214 | module.exports = new Diagnostic_Camera(); 215 | -------------------------------------------------------------------------------- /www/android/diagnostic.contacts.js: -------------------------------------------------------------------------------- 1 | /* globals cordova, require, exports, module */ 2 | 3 | /** 4 | * Diagnostic Contacts plugin for Android 5 | * 6 | * Copyright (c) 2015 Working Edge Ltd. 7 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 8 | **/ 9 | var Diagnostic_Contacts = (function(){ 10 | /*********************** 11 | * 12 | * Internal properties 13 | * 14 | *********************/ 15 | var Diagnostic_Contacts = {}; 16 | 17 | var Diagnostic = require("cordova.plugins.diagnostic.Diagnostic"); 18 | 19 | /******************** 20 | * 21 | * Public properties 22 | * 23 | ********************/ 24 | 25 | /******************** 26 | * 27 | * Internal functions 28 | * 29 | ********************/ 30 | 31 | 32 | /***************************** 33 | * 34 | * Protected member functions 35 | * 36 | ****************************/ 37 | 38 | /********************** 39 | * 40 | * Public API functions 41 | * 42 | **********************/ 43 | 44 | /** 45 | *Checks if the application is authorized to use contacts (address book). 46 | * 47 | * @param {Function} successCallback - The callback which will be called when operation is successful. 48 | * This callback function is passed a single boolean parameter which is TRUE if access to microphone is authorized. 49 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 50 | * This callback function is passed a single string parameter containing the error message. 51 | */ 52 | Diagnostic_Contacts.isContactsAuthorized = function(successCallback, errorCallback) { 53 | function onSuccess(status){ 54 | successCallback(status === Diagnostic.permissionStatus.GRANTED); 55 | } 56 | Diagnostic_Contacts.getContactsAuthorizationStatus(onSuccess, errorCallback); 57 | }; 58 | 59 | /** 60 | * Returns the contacts (address book) authorization status for the application. 61 | * 62 | * @param {Function} successCallback - The callback which will be called when operation is successful. 63 | * This callback function is passed a single string parameter which indicates the authorization status. 64 | * Possible values are: 65 | * `cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED` 66 | * `cordova.plugins.diagnostic.permissionStatus.DENIED_ONCE` 67 | * `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS` 68 | * `cordova.plugins.diagnostic.permissionStatus.GRANTED` 69 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 70 | * This callback function is passed a single string parameter containing the error message. 71 | */ 72 | Diagnostic_Contacts.getContactsAuthorizationStatus = function(successCallback, errorCallback) { 73 | Diagnostic.getPermissionAuthorizationStatus(successCallback, errorCallback, Diagnostic.permission.READ_CONTACTS); 74 | }; 75 | 76 | /** 77 | * Requests contacts (address book) authorization for the application. 78 | * Should only be called if authorization status is NOT_REQUESTED. Calling it when in any other state will have no effect. 79 | * 80 | * @param {Function} successCallback - The callback which will be called when authorization request is successful. 81 | * @param {Function} errorCallback - The callback which will be called when an error occurs. 82 | * This callback function is passed a single string parameter containing the error message. 83 | */ 84 | Diagnostic_Contacts.requestContactsAuthorization = function(successCallback, errorCallback) { 85 | Diagnostic.requestRuntimePermission(successCallback, errorCallback, Diagnostic.permission.READ_CONTACTS); 86 | }; 87 | 88 | 89 | return Diagnostic_Contacts; 90 | }); 91 | module.exports = new Diagnostic_Contacts(); 92 | -------------------------------------------------------------------------------- /www/android/diagnostic.external_storage.js: -------------------------------------------------------------------------------- 1 | /* globals cordova, require, exports, module */ 2 | 3 | /** 4 | * Diagnostic External Storage plugin for Android 5 | * 6 | * Copyright (c) 2015 Working Edge Ltd. 7 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 8 | **/ 9 | var Diagnostic_External_Storage = (function(){ 10 | /*********************** 11 | * 12 | * Internal properties 13 | * 14 | *********************/ 15 | var Diagnostic_External_Storage = {}; 16 | 17 | var Diagnostic = require("cordova.plugins.diagnostic.Diagnostic"); 18 | 19 | /******************** 20 | * 21 | * Public properties 22 | * 23 | ********************/ 24 | 25 | /******************** 26 | * 27 | * Internal functions 28 | * 29 | ********************/ 30 | 31 | 32 | /***************************** 33 | * 34 | * Protected member functions 35 | * 36 | ****************************/ 37 | 38 | /********************** 39 | * 40 | * Public API functions 41 | * 42 | **********************/ 43 | 44 | /** 45 | * Requests authorisation for runtime permission to use the external storage. 46 | * Note: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will have no effect as the permission is already granted at installation time. 47 | * @param {Function} successCallback - function to call on successful request for runtime permission. 48 | * This callback function is passed a single string parameter which defines the resulting authorisation status as a value in cordova.plugins.diagnostic.permissionStatus. 49 | * @param {Function} errorCallback - function to call on failure to request authorisation. 50 | */ 51 | Diagnostic_External_Storage.requestExternalStorageAuthorization = function(successCallback, errorCallback){ 52 | Diagnostic.requestRuntimePermission(successCallback, errorCallback, Diagnostic.permission.READ_EXTERNAL_STORAGE); 53 | }; 54 | 55 | /** 56 | * Returns the authorisation status for runtime permission to use the external storage. 57 | * Note: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return GRANTED status as permission is already granted at installation time. 58 | * @param {Function} successCallback - function to call on successful request for runtime permission status. 59 | * This callback function is passed a single string parameter which defines the current authorisation status as a value in cordova.plugins.diagnostic.permissionStatus. 60 | * @param {Function} errorCallback - function to call on failure to request authorisation status. 61 | */ 62 | Diagnostic_External_Storage.getExternalStorageAuthorizationStatus = function(successCallback, errorCallback){ 63 | Diagnostic.getPermissionAuthorizationStatus(successCallback, errorCallback, Diagnostic.permission.READ_EXTERNAL_STORAGE); 64 | }; 65 | 66 | /** 67 | * Checks if the application is authorized to use external storage. 68 | * Note: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return TRUE as permissions are already granted at installation time. 69 | * @param {Function} successCallback - function to call on successful request for runtime permissions status. 70 | * This callback function is passed a single boolean parameter which is TRUE if the app currently has runtime authorisation to external storage. 71 | * @param {Function} errorCallback - function to call on failure to request authorisation status. 72 | */ 73 | Diagnostic_External_Storage.isExternalStorageAuthorized = function(successCallback, errorCallback){ 74 | function onSuccess(status){ 75 | successCallback(status === Diagnostic.permissionStatus.GRANTED); 76 | } 77 | Diagnostic_External_Storage.getExternalStorageAuthorizationStatus(onSuccess, errorCallback); 78 | }; 79 | 80 | /** 81 | * Returns details of external SD card(s): absolute path, is writable, free space 82 | * @param {Function} successCallback - function to call on successful request for external SD card details. 83 | * This callback function is passed a single argument which is an array consisting of an entry for each external storage location found. 84 | * Each array entry is an object with the following keys: 85 | * - {String} path - absolute path to the storage location 86 | * - {String} filePath - absolute path prefixed with file protocol for use with cordova-plugin-file 87 | * - {Boolean} canWrite - true if the location is writable 88 | * - {Integer} freeSpace - number of bytes of free space on the device on which the storage locaiton is mounted. 89 | * - {String} type - indicates the type of storage location: either "application" if the path is an Android application sandbox path or "root" if the path is the device root. 90 | * @param {Function} errorCallback - function to call on failure to request authorisation status. 91 | */ 92 | Diagnostic_External_Storage.getExternalSdCardDetails = function(successCallback, errorCallback){ 93 | return cordova.exec(successCallback, 94 | errorCallback, 95 | 'Diagnostic_External_Storage', 96 | 'getExternalSdCardDetails', 97 | []); 98 | }; 99 | 100 | return Diagnostic_External_Storage; 101 | }); 102 | module.exports = new Diagnostic_External_Storage(); 103 | -------------------------------------------------------------------------------- /www/android/diagnostic.microphone.js: -------------------------------------------------------------------------------- 1 | /* globals cordova, require, exports, module */ 2 | 3 | /** 4 | * Diagnostic Microphone plugin for Android 5 | * 6 | * Copyright (c) 2015 Working Edge Ltd. 7 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 8 | **/ 9 | var Diagnostic_Microphone = (function(){ 10 | /*********************** 11 | * 12 | * Internal properties 13 | * 14 | *********************/ 15 | var Diagnostic_Microphone = {}; 16 | 17 | var Diagnostic = require("cordova.plugins.diagnostic.Diagnostic"); 18 | 19 | /******************** 20 | * 21 | * Public properties 22 | * 23 | ********************/ 24 | 25 | /******************** 26 | * 27 | * Internal functions 28 | * 29 | ********************/ 30 | 31 | 32 | /***************************** 33 | * 34 | * Protected member functions 35 | * 36 | ****************************/ 37 | 38 | /********************** 39 | * 40 | * Public API functions 41 | * 42 | **********************/ 43 | 44 | /** 45 | * Checks if the application is authorized to use the microphone for recording audio. 46 | * 47 | * @param {Function} successCallback - The callback which will be called when operation is successful. 48 | * This callback function is passed a single boolean parameter which is TRUE if access to microphone is authorized. 49 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 50 | * This callback function is passed a single string parameter containing the error message. 51 | */ 52 | Diagnostic_Microphone.isMicrophoneAuthorized = function(successCallback, errorCallback) { 53 | function onSuccess(status){ 54 | successCallback(status === Diagnostic.permissionStatus.GRANTED); 55 | } 56 | Diagnostic_Microphone.getMicrophoneAuthorizationStatus(onSuccess, errorCallback); 57 | }; 58 | 59 | /** 60 | * Returns the authorization status for the application to use the microphone for recording audio. 61 | * 62 | * @param {Function} successCallback - The callback which will be called when operation is successful. 63 | * This callback function is passed a single string parameter which indicates the authorization status. 64 | * Possible values are: 65 | * `cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED` 66 | * `cordova.plugins.diagnostic.permissionStatus.DENIED_ONCE` 67 | * `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS` 68 | * `cordova.plugins.diagnostic.permissionStatus.GRANTED` 69 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 70 | * This callback function is passed a single string parameter containing the error message. 71 | */ 72 | Diagnostic_Microphone.getMicrophoneAuthorizationStatus = function(successCallback, errorCallback) { 73 | Diagnostic.getPermissionAuthorizationStatus(successCallback, errorCallback, Diagnostic.permission.RECORD_AUDIO); 74 | }; 75 | 76 | /** 77 | * Requests access to microphone if authorization was never granted nor denied, will only return access status otherwise. 78 | * 79 | * @param {Function} successCallback - The callback which will be called when authorization request is successful. 80 | * @param {Function} errorCallback - The callback which will be called when an error occurs. 81 | * This callback function is passed a single string parameter containing the error message. 82 | */ 83 | Diagnostic_Microphone.requestMicrophoneAuthorization = function(successCallback, errorCallback) { 84 | Diagnostic.requestRuntimePermission(successCallback, errorCallback, Diagnostic.permission.RECORD_AUDIO); 85 | }; 86 | 87 | return Diagnostic_Microphone; 88 | }); 89 | module.exports = new Diagnostic_Microphone(); 90 | -------------------------------------------------------------------------------- /www/android/diagnostic.nfc.js: -------------------------------------------------------------------------------- 1 | /* globals cordova, require, exports, module */ 2 | 3 | /** 4 | * Diagnostic NFC plugin for Android 5 | * 6 | * Copyright (c) 2015 Working Edge Ltd. 7 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 8 | **/ 9 | var Diagnostic_NFC = (function(){ 10 | /*********************** 11 | * 12 | * Internal properties 13 | * 14 | *********************/ 15 | var Diagnostic_NFC = {}; 16 | 17 | var Diagnostic = require("cordova.plugins.diagnostic.Diagnostic"); 18 | 19 | /******************** 20 | * 21 | * Public properties 22 | * 23 | ********************/ 24 | 25 | Diagnostic.NFCState = Diagnostic_NFC.NFCState = { 26 | "UNKNOWN": "unknown", 27 | "POWERED_OFF": "powered_off", 28 | "POWERING_ON": "powering_on", 29 | "POWERED_ON": "powered_on", 30 | "POWERING_OFF": "powering_off" 31 | }; 32 | 33 | /******************** 34 | * 35 | * Internal functions 36 | * 37 | ********************/ 38 | 39 | 40 | /***************************** 41 | * 42 | * Protected member functions 43 | * 44 | ****************************/ 45 | // Placeholder listener 46 | Diagnostic_NFC._onNFCStateChange = function(){}; 47 | 48 | /********************** 49 | * 50 | * Public API functions 51 | * 52 | **********************/ 53 | 54 | /** 55 | * Checks if NFC hardware is present on device. 56 | * 57 | * @param {Function} successCallback - The callback which will be called when the operation is successful. 58 | * This callback function is passed a single boolean parameter which is TRUE if NFC is present 59 | * @param {Function} errorCallback - The callback which will be called when the operation encounters an error. 60 | * This callback function is passed a single string parameter containing the error message. 61 | */ 62 | Diagnostic_NFC.isNFCPresent = function(successCallback, errorCallback) { 63 | return cordova.exec(Diagnostic._ensureBoolean(successCallback), 64 | errorCallback, 65 | 'Diagnostic_NFC', 66 | 'isNFCPresent', 67 | []); 68 | }; 69 | 70 | /** 71 | * Checks if the device setting for NFC is switched on. 72 | * 73 | * @param {Function} successCallback - The callback which will be called when the operation is successful. 74 | * This callback function is passed a single boolean parameter which is TRUE if NFC is switched on. 75 | * @param {Function} errorCallback - The callback which will be called when the operation encounters an error. 76 | * This callback function is passed a single string parameter containing the error message. 77 | */ 78 | Diagnostic_NFC.isNFCEnabled = function(successCallback, errorCallback) { 79 | return cordova.exec(Diagnostic._ensureBoolean(successCallback), 80 | errorCallback, 81 | 'Diagnostic_NFC', 82 | 'isNFCEnabled', 83 | []); 84 | }; 85 | 86 | /** 87 | * Checks if NFC is available to the app. 88 | * Returns true if the device has NFC capabilities and if so that NFC is switched on. 89 | * 90 | * @param {Function} successCallback - The callback which will be called when the operation is successful. 91 | * This callback function is passed a single boolean parameter which is TRUE if NFC is available. 92 | * @param {Function} errorCallback - The callback which will be called when the operation encounters an error. 93 | * This callback function is passed a single string parameter containing the error message. 94 | */ 95 | Diagnostic_NFC.isNFCAvailable = function(successCallback, errorCallback) { 96 | return cordova.exec(Diagnostic._ensureBoolean(successCallback), 97 | errorCallback, 98 | 'Diagnostic_NFC', 99 | 'isNFCAvailable', 100 | []); 101 | }; 102 | 103 | /** 104 | * Registers a function to be called when a change in NFC state occurs. 105 | * Pass in a falsey value to de-register the currently registered function. 106 | * 107 | * @param {Function} successCallback - The callback which will be called when the NFC state changes. 108 | * This callback function is passed a single string parameter defined as a constant in `cordova.plugins.diagnostic.NFCState`. 109 | */ 110 | Diagnostic_NFC.registerNFCStateChangeHandler = function(successCallback) { 111 | Diagnostic_NFC._onNFCStateChange = successCallback || function(){}; 112 | }; 113 | 114 | /** 115 | * Switches to the nfc settings page in the Settings app 116 | */ 117 | Diagnostic_NFC.switchToNFCSettings = function() { 118 | return cordova.exec(null, 119 | null, 120 | 'Diagnostic_NFC', 121 | 'switchToNFCSettings', 122 | []); 123 | }; 124 | 125 | return Diagnostic_NFC; 126 | }); 127 | module.exports = new Diagnostic_NFC(); -------------------------------------------------------------------------------- /www/android/diagnostic.notifications.js: -------------------------------------------------------------------------------- 1 | /* globals cordova, require, exports, module */ 2 | 3 | /** 4 | * Diagnostic Notifications plugin for Android 5 | * 6 | * Copyright (c) 2015 Working Edge Ltd. 7 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 8 | **/ 9 | var Diagnostic_Notifications = (function(){ 10 | /*********************** 11 | * 12 | * Internal properties 13 | * 14 | *********************/ 15 | var Diagnostic_Notifications = {}; 16 | 17 | var Diagnostic = require("cordova.plugins.diagnostic.Diagnostic"); 18 | 19 | /******************** 20 | * 21 | * Public properties 22 | * 23 | ********************/ 24 | 25 | /******************** 26 | * 27 | * Internal functions 28 | * 29 | ********************/ 30 | 31 | 32 | /***************************** 33 | * 34 | * Protected member functions 35 | * 36 | ****************************/ 37 | 38 | /********************** 39 | * 40 | * Public API functions 41 | * 42 | **********************/ 43 | 44 | /** 45 | * Checks if remote notifications is available to the app. 46 | * Returns true if remote notifications are switched on. 47 | * 48 | * @param {Function} successCallback - The callback which will be called when the operation is successful. 49 | * This callback function is passed a single boolean parameter which is TRUE if remote notifications is available. 50 | * @param {Function} errorCallback - The callback which will be called when the operation encounters an error. 51 | * This callback function is passed a single string parameter containing the error message. 52 | */ 53 | Diagnostic_Notifications.isRemoteNotificationsEnabled = function(successCallback, errorCallback) { 54 | return cordova.exec(Diagnostic._ensureBoolean(successCallback), 55 | errorCallback, 56 | 'Diagnostic_Notifications', 57 | 'isRemoteNotificationsEnabled', 58 | []); 59 | }; 60 | 61 | /** 62 | * Switches to the notifications page in the Settings app 63 | */ 64 | Diagnostic_Notifications.switchToNotificationSettings = function() { 65 | return cordova.exec(null, 66 | null, 67 | 'Diagnostic_Notifications', 68 | 'switchToNotificationSettings', 69 | []); 70 | }; 71 | 72 | return Diagnostic_Notifications; 73 | }); 74 | module.exports = new Diagnostic_Notifications(); -------------------------------------------------------------------------------- /www/android/diagnostic.wifi.js: -------------------------------------------------------------------------------- 1 | /* globals cordova, require, exports, module */ 2 | 3 | /** 4 | * Diagnostic Wifi plugin for Android 5 | * 6 | * Copyright (c) 2015 Working Edge Ltd. 7 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 8 | **/ 9 | var Diagnostic_Wifi = (function(){ 10 | /*********************** 11 | * 12 | * Internal properties 13 | * 14 | *********************/ 15 | var Diagnostic_Wifi = {}; 16 | 17 | var Diagnostic = require("cordova.plugins.diagnostic.Diagnostic"); 18 | 19 | /******************** 20 | * 21 | * Public properties 22 | * 23 | ********************/ 24 | 25 | /******************** 26 | * 27 | * Internal functions 28 | * 29 | ********************/ 30 | 31 | 32 | /***************************** 33 | * 34 | * Protected member functions 35 | * 36 | ****************************/ 37 | 38 | /********************** 39 | * 40 | * Public API functions 41 | * 42 | **********************/ 43 | 44 | /** 45 | * Checks if Wifi is enabled. 46 | * On Android this returns true if the WiFi setting is set to enabled. 47 | * 48 | * @param {Function} successCallback - The callback which will be called when the operation is successful. 49 | * This callback function is passed a single boolean parameter which is TRUE if WiFi is enabled. 50 | * @param {Function} errorCallback - The callback which will be called when the operation encounters an error. 51 | * This callback function is passed a single string parameter containing the error message. 52 | */ 53 | Diagnostic_Wifi.isWifiAvailable = Diagnostic_Wifi.isWifiEnabled = function(successCallback, errorCallback) { 54 | return cordova.exec(successCallback, 55 | errorCallback, 56 | 'Diagnostic_Wifi', 57 | 'isWifiAvailable', 58 | []); 59 | }; 60 | 61 | /** 62 | * Switches to the WiFi page in the Settings app 63 | */ 64 | Diagnostic_Wifi.switchToWifiSettings = function() { 65 | return cordova.exec(null, 66 | null, 67 | 'Diagnostic_Wifi', 68 | 'switchToWifiSettings', 69 | []); 70 | }; 71 | 72 | /** 73 | * Enables/disables WiFi on the device. 74 | * 75 | * @param {Function} successCallback - function to call on successful setting of WiFi state 76 | * @param {Function} errorCallback - function to call on failure to set WiFi state. 77 | * This callback function is passed a single string parameter containing the error message. 78 | * @param {Boolean} state - WiFi state to set: TRUE for enabled, FALSE for disabled. 79 | */ 80 | Diagnostic_Wifi.setWifiState = function(successCallback, errorCallback, state) { 81 | return cordova.exec(successCallback, 82 | errorCallback, 83 | 'Diagnostic_Wifi', 84 | 'setWifiState', 85 | [state]); 86 | }; 87 | 88 | return Diagnostic_Wifi; 89 | }); 90 | module.exports = new Diagnostic_Wifi(); -------------------------------------------------------------------------------- /www/ios/diagnostic.bluetooth.js: -------------------------------------------------------------------------------- 1 | /* globals cordova, require, exports, module */ 2 | 3 | /** 4 | * Diagnostic Bluetooth plugin for iOS 5 | * 6 | * Copyright (c) 2015 Working Edge Ltd. 7 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 8 | **/ 9 | var Diagnostic_Bluetooth = (function(){ 10 | /*********************** 11 | * 12 | * Internal properties 13 | * 14 | *********************/ 15 | var Diagnostic_Bluetooth = {}; 16 | 17 | var Diagnostic = require("cordova.plugins.diagnostic.Diagnostic"); 18 | 19 | /******************** 20 | * 21 | * Public properties 22 | * 23 | ********************/ 24 | 25 | Diagnostic.bluetoothState = Diagnostic_Bluetooth.bluetoothState = { 26 | "UNKNOWN": "unknown", 27 | "RESETTING": "resetting", 28 | "UNSUPPORTED": "unsupported", 29 | "UNAUTHORIZED": "unauthorized", 30 | "POWERED_OFF": "powered_off", 31 | "POWERED_ON": "powered_on" 32 | }; 33 | 34 | 35 | 36 | /******************** 37 | * 38 | * Internal functions 39 | * 40 | ********************/ 41 | 42 | /***************************** 43 | * 44 | * Protected member functions 45 | * 46 | ****************************/ 47 | Diagnostic_Bluetooth._onBluetoothStateChange = function(){}; 48 | 49 | 50 | /********************** 51 | * 52 | * Public API functions 53 | * 54 | **********************/ 55 | 56 | /** 57 | * Checks if the device has Bluetooth LE capabilities and if so that Bluetooth is switched on 58 | * 59 | * @param {Function} successCallback - The callback which will be called when operation is successful. 60 | * This callback function is passed a single boolean parameter which is TRUE if device has Bluetooth LE and Bluetooth is switched on. 61 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 62 | * This callback function is passed a single string parameter containing the error message. 63 | */ 64 | Diagnostic_Bluetooth.isBluetoothAvailable = function(successCallback, errorCallback) { 65 | return cordova.exec(Diagnostic._ensureBoolean(successCallback), 66 | errorCallback, 67 | 'Diagnostic_Bluetooth', 68 | 'isBluetoothAvailable', 69 | []); 70 | }; 71 | 72 | /** 73 | * Returns the state of Bluetooth LE on the device. 74 | * 75 | * @param {Function} successCallback - The callback which will be called when operation is successful. 76 | * This callback function is passed a single string parameter which indicates the Bluetooth state as a constant in `cordova.plugins.diagnostic.bluetoothState`. 77 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 78 | * This callback function is passed a single string parameter containing the error message. 79 | */ 80 | Diagnostic_Bluetooth.getBluetoothState = function(successCallback, errorCallback) { 81 | return cordova.exec(successCallback, 82 | errorCallback, 83 | 'Diagnostic_Bluetooth', 84 | 'getBluetoothState', 85 | []); 86 | }; 87 | 88 | 89 | /** 90 | * Registers a function to be called when a change in Bluetooth state occurs. 91 | * Pass in a falsey value to de-register the currently registered function. 92 | * 93 | * @param {Function} successCallback - function call when a change in Bluetooth state occurs. 94 | * This callback function is passed a single string parameter which indicates the Bluetooth state as a constant in `cordova.plugins.diagnostic.bluetoothState`. 95 | */ 96 | Diagnostic_Bluetooth.registerBluetoothStateChangeHandler = function(successCallback){ 97 | Diagnostic_Bluetooth._onBluetoothStateChange = successCallback || function(){}; 98 | return cordova.exec(successCallback, 99 | null, 100 | 'Diagnostic_Bluetooth', 101 | 'ensureBluetoothManager', 102 | []); 103 | }; 104 | 105 | /** 106 | * Requests Bluetooth authorization for the application. 107 | * The outcome of the authorization request can be determined by registering a handler using `registerBluetoothStateChangeHandler()`. 108 | * 109 | * @param {Function} successCallback - The callback which will be called when operation is successful. 110 | * This callback function is not passed any parameters. 111 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 112 | * This callback function is passed a single string parameter containing the error message. 113 | */ 114 | Diagnostic_Bluetooth.requestBluetoothAuthorization = function(successCallback, errorCallback) { 115 | return cordova.exec( 116 | successCallback, 117 | errorCallback, 118 | 'Diagnostic_Bluetooth', 119 | 'requestBluetoothAuthorization', 120 | []); 121 | }; 122 | 123 | /** 124 | * Returns the Bluetooth authorization status for the application. 125 | * On iOS 12 and below, authorization is not required so will always be GRANTED 126 | * 127 | * @param {Function} successCallback - The callback which will be called when operation is successful. 128 | * This callback function is passed a single string parameter which indicates the authorization status as a constant in `cordova.plugins.diagnostic.permissionStatus`. 129 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 130 | * This callback function is passed a single string parameter containing the error message. 131 | */ 132 | Diagnostic_Bluetooth.getAuthorizationStatus = function(successCallback, errorCallback) { 133 | return cordova.exec(successCallback, 134 | errorCallback, 135 | 'Diagnostic_Bluetooth', 136 | 'getAuthorizationStatus', 137 | []); 138 | }; 139 | 140 | 141 | return Diagnostic_Bluetooth; 142 | }); 143 | module.exports = new Diagnostic_Bluetooth(); -------------------------------------------------------------------------------- /www/ios/diagnostic.calendar.js: -------------------------------------------------------------------------------- 1 | /* globals cordova, require, exports, module */ 2 | 3 | /** 4 | * Diagnostic Calendar plugin for iOS 5 | * 6 | * Copyright (c) 2015 Working Edge Ltd. 7 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 8 | **/ 9 | var Diagnostic_Calendar = (function(){ 10 | /*********************** 11 | * 12 | * Internal properties 13 | * 14 | *********************/ 15 | var Diagnostic_Calendar = {}; 16 | 17 | var Diagnostic = require("cordova.plugins.diagnostic.Diagnostic"); 18 | 19 | /******************** 20 | * 21 | * Public properties 22 | * 23 | ********************/ 24 | 25 | /******************** 26 | * 27 | * Internal functions 28 | * 29 | ********************/ 30 | 31 | /***************************** 32 | * 33 | * Protected member functions 34 | * 35 | ****************************/ 36 | 37 | 38 | /********************** 39 | * 40 | * Public API functions 41 | * 42 | **********************/ 43 | /** 44 | * Checks if the application is authorized to use calendar. 45 | * 46 | * @param {Function} successCallback - The callback which will be called when operation is successful. 47 | * This callback function is passed a single boolean parameter which is TRUE if calendar is authorized for use. 48 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 49 | * This callback function is passed a single string parameter containing the error message. 50 | */ 51 | Diagnostic_Calendar.isCalendarAuthorized = function(successCallback, errorCallback) { 52 | return cordova.exec(Diagnostic._ensureBoolean(successCallback), 53 | errorCallback, 54 | 'Diagnostic_Calendar', 55 | 'isCalendarAuthorized', 56 | []); 57 | }; 58 | 59 | /** 60 | * Returns the calendar event authorization status for the application. 61 | * 62 | * @param {Function} successCallback - The callback which will be called when operation is successful. 63 | * This callback function is passed a single string parameter which indicates the authorization status as a constant in `cordova.plugins.diagnostic.permissionStatus`. 64 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 65 | * This callback function is passed a single string parameter containing the error message. 66 | */ 67 | Diagnostic_Calendar.getCalendarAuthorizationStatus = function(successCallback, errorCallback) { 68 | return cordova.exec(successCallback, 69 | errorCallback, 70 | 'Diagnostic_Calendar', 71 | 'getCalendarAuthorizationStatus', 72 | []); 73 | }; 74 | 75 | /** 76 | * Requests calendar event authorization for the application. 77 | * Should only be called if authorization status is NOT_REQUESTED. Calling it when in any other state will have no effect. 78 | * 79 | * @param {Function} successCallback - The callback which will be called when operation is successful. 80 | * This callback function is passed a single string parameter indicating whether access to calendar was granted or denied: 81 | * `cordova.plugins.diagnostic.permissionStatus.GRANTED` or `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS` 82 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 83 | * This callback function is passed a single string parameter containing the error message. 84 | */ 85 | Diagnostic_Calendar.requestCalendarAuthorization = function(successCallback, errorCallback) { 86 | return cordova.exec(function(isGranted){ 87 | successCallback(isGranted ? Diagnostic.permissionStatus.GRANTED : Diagnostic.permissionStatus.DENIED_ALWAYS); 88 | }, 89 | errorCallback, 90 | 'Diagnostic_Calendar', 91 | 'requestCalendarAuthorization', 92 | []); 93 | }; 94 | 95 | return Diagnostic_Calendar; 96 | }); 97 | module.exports = new Diagnostic_Calendar(); 98 | -------------------------------------------------------------------------------- /www/ios/diagnostic.contacts.js: -------------------------------------------------------------------------------- 1 | /* globals cordova, require, exports, module */ 2 | 3 | /** 4 | * Diagnostic Contacts plugin for iOS 5 | * 6 | * Copyright (c) 2015 Working Edge Ltd. 7 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 8 | **/ 9 | var Diagnostic_Contacts = (function(){ 10 | /*********************** 11 | * 12 | * Internal properties 13 | * 14 | *********************/ 15 | var Diagnostic_Contacts = {}; 16 | 17 | var Diagnostic = require("cordova.plugins.diagnostic.Diagnostic"); 18 | 19 | /******************** 20 | * 21 | * Public properties 22 | * 23 | ********************/ 24 | 25 | /******************** 26 | * 27 | * Internal functions 28 | * 29 | ********************/ 30 | 31 | /***************************** 32 | * 33 | * Protected member functions 34 | * 35 | ****************************/ 36 | 37 | 38 | /********************** 39 | * 40 | * Public API functions 41 | * 42 | **********************/ 43 | 44 | /** 45 | * Checks if the application is authorized to use contacts (address book). 46 | * 47 | * @param {Function} successCallback - The callback which will be called when operation is successful. 48 | * This callback function is passed a single boolean parameter which is TRUE if contacts is authorized for use. 49 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 50 | * This callback function is passed a single string parameter containing the error message. 51 | */ 52 | Diagnostic_Contacts.isContactsAuthorized = function(successCallback, errorCallback) { 53 | return cordova.exec(Diagnostic._ensureBoolean(successCallback), 54 | errorCallback, 55 | 'Diagnostic_Contacts', 56 | 'isAddressBookAuthorized', 57 | []); 58 | }; 59 | 60 | /** 61 | * Returns the contacts (address book) authorization status for the application. 62 | * 63 | * @param {Function} successCallback - The callback which will be called when operation is successful. 64 | * This callback function is passed a single string parameter which indicates the authorization status as a constant in `cordova.plugins.diagnostic.permissionStatus`. 65 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 66 | * This callback function is passed a single string parameter containing the error message. 67 | */ 68 | Diagnostic_Contacts.getContactsAuthorizationStatus = function(successCallback, errorCallback) { 69 | return cordova.exec(successCallback, 70 | errorCallback, 71 | 'Diagnostic_Contacts', 72 | 'getAddressBookAuthorizationStatus', 73 | []); 74 | }; 75 | 76 | /** 77 | * Requests contacts (address book) authorization for the application. 78 | * Should only be called if authorization status is NOT_REQUESTED. Calling it when in any other state will have no effect. 79 | * 80 | * @param {Function} successCallback - The callback which will be called when operation is successful. 81 | * This callback function is passed a single string parameter indicating whether access to contacts was granted or denied: 82 | * `cordova.plugins.diagnostic.permissionStatus.GRANTED` or `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS` 83 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 84 | * This callback function is passed a single string parameter containing the error message. 85 | */ 86 | Diagnostic_Contacts.requestContactsAuthorization = function(successCallback, errorCallback) { 87 | return cordova.exec(function(isGranted){ 88 | successCallback(isGranted ? Diagnostic.permissionStatus.GRANTED : Diagnostic.permissionStatus.DENIED_ALWAYS); 89 | }, 90 | errorCallback, 91 | 'Diagnostic_Contacts', 92 | 'requestAddressBookAuthorization', 93 | []); 94 | }; 95 | 96 | return Diagnostic_Contacts; 97 | }); 98 | module.exports = new Diagnostic_Contacts(); 99 | -------------------------------------------------------------------------------- /www/ios/diagnostic.location.js: -------------------------------------------------------------------------------- 1 | /* globals cordova, require, exports, module */ 2 | 3 | /** 4 | * Diagnostic Location plugin for iOS 5 | * 6 | * Copyright (c) 2015 Working Edge Ltd. 7 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 8 | **/ 9 | var Diagnostic_Location = (function(){ 10 | /*********************** 11 | * 12 | * Internal properties 13 | * 14 | *********************/ 15 | var Diagnostic_Location = {}; 16 | 17 | var Diagnostic = require("cordova.plugins.diagnostic.Diagnostic"); 18 | 19 | /******************** 20 | * 21 | * Public properties 22 | * 23 | ********************/ 24 | 25 | Diagnostic.locationAuthorizationMode = Diagnostic_Location.locationAuthorizationMode = { 26 | "ALWAYS": "always", 27 | "WHEN_IN_USE": "when_in_use" 28 | }; 29 | 30 | Diagnostic.locationAccuracyAuthorization = Diagnostic_Location.locationAccuracyAuthorization = { 31 | "FULL": "full", 32 | "REDUCED": "reduced" 33 | }; 34 | 35 | /******************** 36 | * 37 | * Internal functions 38 | * 39 | ********************/ 40 | 41 | /***************************** 42 | * 43 | * Protected member functions 44 | * 45 | ****************************/ 46 | Diagnostic_Location._onLocationStateChange = function(){}; 47 | Diagnostic_Location._onLocationAccuracyAuthorizationChange = function(){}; 48 | 49 | 50 | /********************** 51 | * 52 | * Public API functions 53 | * 54 | **********************/ 55 | 56 | /** 57 | * Checks if location is available for use by the app. 58 | * On iOS this returns true if both the device setting for Location Services is ON AND the application is authorized to use location. 59 | * When location is enabled, the locations returned are by a mixture GPS hardware, network triangulation and Wifi network IDs. 60 | * 61 | * @param {Function} successCallback - The callback which will be called when operation is successful. 62 | * This callback function is passed a single boolean parameter which is TRUE if location is available for use. 63 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 64 | * This callback function is passed a single string parameter containing the error message. 65 | */ 66 | Diagnostic_Location.isLocationAvailable = function(successCallback, errorCallback) { 67 | return cordova.exec(Diagnostic._ensureBoolean(successCallback), 68 | errorCallback, 69 | 'Diagnostic_Location', 70 | 'isLocationAvailable', 71 | []); 72 | }; 73 | 74 | /** 75 | * Checks if the device location setting is enabled. 76 | * Returns true if Location Services is enabled. 77 | * 78 | * @param {Function} successCallback - The callback which will be called when operation is successful. 79 | * This callback function is passed a single boolean parameter which is TRUE if Location Services is enabled. 80 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 81 | * This callback function is passed a single string parameter containing the error message. 82 | */ 83 | Diagnostic_Location.isLocationEnabled = function(successCallback, errorCallback) { 84 | return cordova.exec(Diagnostic._ensureBoolean(successCallback), 85 | errorCallback, 86 | 'Diagnostic_Location', 87 | 'isLocationEnabled', 88 | []); 89 | }; 90 | 91 | 92 | /** 93 | * Checks if the application is authorized to use location. 94 | * 95 | * @param {Function} successCallback - The callback which will be called when operation is successful. 96 | * 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). 97 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 98 | * This callback function is passed a single string parameter containing the error message. 99 | */ 100 | Diagnostic_Location.isLocationAuthorized = function(successCallback, errorCallback) { 101 | return cordova.exec(Diagnostic._ensureBoolean(successCallback), 102 | errorCallback, 103 | 'Diagnostic_Location', 104 | 'isLocationAuthorized', 105 | []); 106 | }; 107 | 108 | /** 109 | * Returns the location authorization status for the application. 110 | * 111 | * @param {Function} successCallback - The callback which will be called when operation is successful. 112 | * This callback function is passed a single string parameter which indicates the location authorization status as a constant in `cordova.plugins.diagnostic.permissionStatus`. 113 | * Possible values are: 114 | * `cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED` 115 | * `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS` 116 | * `cordova.plugins.diagnostic.permissionStatus.GRANTED` 117 | * `cordova.plugins.diagnostic.permissionStatus.GRANTED_WHEN_IN_USE` 118 | * Note that `GRANTED` indicates the app is always granted permission (even when in background). 119 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 120 | * This callback function is passed a single string parameter containing the error message. 121 | */ 122 | Diagnostic_Location.getLocationAuthorizationStatus = function(successCallback, errorCallback) { 123 | return cordova.exec(successCallback, 124 | errorCallback, 125 | 'Diagnostic_Location', 126 | 'getLocationAuthorizationStatus', 127 | []); 128 | }; 129 | 130 | /** 131 | * Returns the location accuracy authorization for the application. 132 | * 133 | * @param {Function} successCallback - The callback which will be called when operation is successful. 134 | * This callback function is passed a single string parameter which indicates the location accuracy authorization as a constant in `cordova.plugins.diagnostic.locationAccuracyAuthorization`. 135 | * Possible values are: 136 | * `cordova.plugins.diagnostic.locationAccuracyAuthorization.FULL` 137 | * `cordova.plugins.diagnostic.locationAccuracyAuthorization.REDUCED` 138 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 139 | * This callback function is passed a single string parameter containing the error message. 140 | */ 141 | Diagnostic_Location.getLocationAccuracyAuthorization = function(successCallback, errorCallback) { 142 | return cordova.exec(successCallback, 143 | errorCallback, 144 | 'Diagnostic_Location', 145 | 'getLocationAccuracyAuthorization', 146 | []); 147 | }; 148 | 149 | /** 150 | * Requests location authorization for the application. 151 | * Authorization can be requested to use location either "when in use" (only in foreground) or "always" (foreground and background). 152 | * Should only be called if authorization status is NOT_REQUESTED. Calling it when in any other state will have no effect. 153 | * 154 | * @param {Function} successCallback - Invoked in response to the user's choice in the permission dialog. 155 | * It is passed a single string parameter which defines the resulting authorisation status as a constant in `cordova.plugins.diagnostic.permissionStatus`. 156 | * Possible values are: 157 | * `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS` 158 | * `cordova.plugins.diagnostic.permissionStatus.GRANTED` 159 | * `cordova.plugins.diagnostic.permissionStatus.GRANTED_WHEN_IN_USE` 160 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 161 | * This callback function is passed a single string parameter containing the error message. 162 | * @param {String} mode - (optional) location authorization mode as a constant in `cordova.plugins.diagnostic.locationAuthorizationMode`. 163 | * If not specified, defaults to `cordova.plugins.diagnostic.locationAuthorizationMode.WHEN_IN_USE`. 164 | */ 165 | Diagnostic_Location.requestLocationAuthorization = function(successCallback, errorCallback, mode) { 166 | return cordova.exec(successCallback, 167 | errorCallback, 168 | 'Diagnostic_Location', 169 | 'requestLocationAuthorization', 170 | [mode && mode === Diagnostic_Location.locationAuthorizationMode.ALWAYS]); 171 | }; 172 | 173 | /** 174 | * Requests temporary access to full location accuracy for the application. 175 | * By default on iOS 14+, when a user grants location permission, the app can only receive reduced accuracy locations. 176 | * If your app requires full (high-accuracy GPS) locations (e.g. a SatNav app), you need to call this method. 177 | * Should only be called if location authorization has been granted. 178 | * 179 | * @param {String} purpose - (required) corresponds to a key in the NSLocationTemporaryUsageDescriptionDictionary entry in your app's `*-Info.plist` 180 | * which contains a message explaining the user why your app needs their exact location. 181 | * This will be presented to the user via permission dialog in which they can either accept or reject the request. 182 | * @param {Function} successCallback - (optional) Invoked in response to the user's choice in the permission dialog. 183 | * It is passed a single string parameter which defines the resulting accuracy authorization as a constant in `cordova.plugins.diagnostic.locationAccuracyAuthorization`. 184 | * Possible values are: 185 | * `cordova.plugins.diagnostic.locationAccuracyAuthorization.FULL` 186 | * `cordova.plugins.diagnostic.locationAccuracyAuthorization.REDUCED` 187 | * @param {Function} errorCallback - (optional) The callback which will be called when operation encounters an error. 188 | * This callback function is passed a single string parameter containing the error message. 189 | */ 190 | Diagnostic_Location.requestTemporaryFullAccuracyAuthorization = function(purpose, successCallback, errorCallback) { 191 | if(typeof purpose !== "string"){ 192 | var errMessage = "'purpose' must be specified"; 193 | if(errorCallback){ 194 | return errorCallback(errMessage); 195 | } 196 | throw errMessage; 197 | } 198 | return cordova.exec(successCallback, 199 | errorCallback, 200 | 'Diagnostic_Location', 201 | 'requestTemporaryFullAccuracyAuthorization', 202 | [purpose]); 203 | }; 204 | 205 | /** 206 | * Registers a function to be called when a change in Location state occurs. 207 | * On iOS, this occurs when location authorization status is changed. 208 | * This can be triggered either by the user's response to a location permission authorization dialog, 209 | * by the user turning on/off Location Services, 210 | * or by the user changing the Location authorization state specifically for your app. 211 | * Pass in a falsey value to de-register the currently registered function. 212 | * 213 | * @param {Function} successCallback - The callback which will be called when the Location state changes. 214 | * This callback function is passed a single string parameter indicating the new location authorisation status as a constant in `cordova.plugins.diagnostic.permissionStatus`. 215 | */ 216 | Diagnostic_Location.registerLocationStateChangeHandler = function(successCallback) { 217 | Diagnostic_Location._onLocationStateChange = successCallback || function(){}; 218 | }; 219 | 220 | /** 221 | * Registers a function to be called when a change in location accuracy authorization occurs. 222 | * This occurs when location accuracy authorization is changed. 223 | * This can be triggered either by the user's response to a location accuracy authorization dialog, 224 | * or by the user changing the location accuracy authorization specifically for your app in Settings. 225 | * Pass in a falsey value to de-register the currently registered function. 226 | * 227 | * @param {Function} successCallback - The callback which will be called when the location accuracy authorization changes. 228 | * This callback function is passed a single string parameter indicating the new location accuracy authorization as a constant in `cordova.plugins.diagnostic.locationAccuracyAuthorization`. 229 | */ 230 | Diagnostic_Location.registerLocationAccuracyAuthorizationChangeHandler = function(successCallback) { 231 | Diagnostic_Location._onLocationAccuracyAuthorizationChange = successCallback || function(){}; 232 | }; 233 | 234 | return Diagnostic_Location; 235 | }); 236 | module.exports = new Diagnostic_Location(); 237 | -------------------------------------------------------------------------------- /www/ios/diagnostic.microphone.js: -------------------------------------------------------------------------------- 1 | /* globals cordova, require, exports, module */ 2 | 3 | /** 4 | * Diagnostic Microphone plugin for iOS 5 | * 6 | * Copyright (c) 2015 Working Edge Ltd. 7 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 8 | **/ 9 | var Diagnostic_Microphone = (function(){ 10 | /*********************** 11 | * 12 | * Internal properties 13 | * 14 | *********************/ 15 | var Diagnostic_Microphone = {}; 16 | 17 | var Diagnostic = require("cordova.plugins.diagnostic.Diagnostic"); 18 | 19 | /******************** 20 | * 21 | * Public properties 22 | * 23 | ********************/ 24 | 25 | /******************** 26 | * 27 | * Internal functions 28 | * 29 | ********************/ 30 | 31 | /***************************** 32 | * 33 | * Protected member functions 34 | * 35 | ****************************/ 36 | 37 | 38 | /********************** 39 | * 40 | * Public API functions 41 | * 42 | **********************/ 43 | 44 | /** 45 | * Checks if the application is authorized to use the microphone for recording audio. 46 | * 47 | * @param {Function} successCallback - The callback which will be called when operation is successful. 48 | * This callback function is passed a single boolean parameter which is TRUE if access to microphone is authorized. 49 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 50 | * This callback function is passed a single string parameter containing the error message. 51 | */ 52 | Diagnostic_Microphone.isMicrophoneAuthorized = function(successCallback, errorCallback) { 53 | return cordova.exec(Diagnostic._ensureBoolean(successCallback), 54 | errorCallback, 55 | 'Diagnostic_Microphone', 56 | 'isMicrophoneAuthorized', 57 | []); 58 | }; 59 | 60 | /** 61 | * Returns the authorization status for the application to use the microphone for recording audio. 62 | * 63 | * @param {Function} successCallback - The callback which will be called when operation is successful. 64 | * This callback function is passed a single string parameter which indicates the authorization status as a constant in `cordova.plugins.diagnostic.permissionStatus`. 65 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 66 | * This callback function is passed a single string parameter containing the error message. 67 | */ 68 | Diagnostic_Microphone.getMicrophoneAuthorizationStatus = function(successCallback, errorCallback) { 69 | return cordova.exec(successCallback, 70 | errorCallback, 71 | 'Diagnostic_Microphone', 72 | 'getMicrophoneAuthorizationStatus', 73 | []); 74 | }; 75 | 76 | /** 77 | * Requests access to microphone if authorization was never granted nor denied, will only return access status otherwise. 78 | * 79 | * @param {Function} successCallback - The callback which will be called when operation is successful. 80 | * This callback function is passed a single string parameter indicating whether access to the microphone was granted or denied: 81 | * `cordova.plugins.diagnostic.permissionStatus.GRANTED` or `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS` 82 | * @param {Function} errorCallback - The callback which will be called when an error occurs. 83 | * This callback function is passed a single string parameter containing the error message. 84 | */ 85 | Diagnostic_Microphone.requestMicrophoneAuthorization = function(successCallback, errorCallback) { 86 | return cordova.exec(function(isGranted){ 87 | successCallback(isGranted ? Diagnostic.permissionStatus.GRANTED : Diagnostic.permissionStatus.DENIED_ALWAYS); 88 | }, 89 | errorCallback, 90 | 'Diagnostic_Microphone', 91 | 'requestMicrophoneAuthorization', 92 | []); 93 | }; 94 | 95 | 96 | 97 | return Diagnostic_Microphone; 98 | }); 99 | module.exports = new Diagnostic_Microphone(); 100 | -------------------------------------------------------------------------------- /www/ios/diagnostic.motion.js: -------------------------------------------------------------------------------- 1 | /* globals cordova, require, exports, module */ 2 | 3 | /** 4 | * Diagnostic Motion plugin for iOS 5 | * 6 | * Copyright (c) 2015 Working Edge Ltd. 7 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 8 | **/ 9 | var Diagnostic_Motion = (function(){ 10 | /*********************** 11 | * 12 | * Internal properties 13 | * 14 | *********************/ 15 | var Diagnostic_Motion = {}; 16 | 17 | var Diagnostic = require("cordova.plugins.diagnostic.Diagnostic"); 18 | 19 | /******************** 20 | * 21 | * Public properties 22 | * 23 | ********************/ 24 | 25 | /** 26 | * Status of motion+tracking permission 27 | * @type {object} 28 | */ 29 | Diagnostic.motionStatus = Diagnostic_Motion.motionStatus = { 30 | "UNKNOWN": "unknown", // Status is not known 31 | "NOT_REQUESTED": "not_requested", // App has not yet requested this permission 32 | "DENIED_ALWAYS": "denied_always", // User denied access to this permission 33 | "RESTRICTED": "restricted", // Permission is unavailable and user cannot enable it. For example, when parental controls are in effect for the current user. 34 | "GRANTED": "authorized", // User granted access to this permission 35 | "NOT_AVAILABLE": "not_available", // Motion tracking not available on device 36 | "NOT_DETERMINED": "not_determined" // Motion authorization request status outcome cannot be determined on device 37 | }; 38 | 39 | /******************** 40 | * 41 | * Internal functions 42 | * 43 | ********************/ 44 | 45 | 46 | /***************************** 47 | * 48 | * Protected member functions 49 | * 50 | ****************************/ 51 | 52 | 53 | /********************** 54 | * 55 | * Public API functions 56 | * 57 | **********************/ 58 | 59 | /** 60 | * Checks if motion tracking is available on the current device. 61 | * Motion tracking is supported by iOS devices with an M7 co-processor (or above): that is iPhone 5s (or above), iPad Air (or above), iPad Mini 2 (or above). 62 | * 63 | * @param {Function} successCallback - The callback which will be called when operation is successful. 64 | * This callback function is passed a single boolean parameter which is TRUE if motion tracking is available on the current device. 65 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 66 | * This callback function is passed a single string parameter containing the error message. 67 | */ 68 | Diagnostic_Motion.isMotionAvailable = function(successCallback, errorCallback) { 69 | return cordova.exec(Diagnostic._ensureBoolean(successCallback), 70 | errorCallback, 71 | 'Diagnostic_Motion', 72 | 'isMotionAvailable', 73 | []); 74 | }; 75 | 76 | /** 77 | * Checks if it's possible to determine the outcome of a motion authorization request on the current device. 78 | * There's no direct way to determine if authorization was granted or denied, so the Pedometer API must be used to indirectly determine this. 79 | * Therefore, if the device supports motion tracking but not Pedometer Event Tracking, while Motion Track permission can be requested, the outcome of the request cannot be determined. 80 | * Pedometer Event Tracking is only available on iPhones with an M7 co-processor (or above): that is iPhone 5s (or above). No iPads yet support it. 81 | * 82 | * @param {Function} successCallback - The callback which will be called when operation is successful. 83 | * This callback function is passed a single boolean parameter which is TRUE if it's possible to determine the outcome of a motion authorization request on the current device. 84 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 85 | * This callback function is passed a single string parameter containing the error message. 86 | */ 87 | Diagnostic_Motion.isMotionRequestOutcomeAvailable = function(successCallback, errorCallback) { 88 | return cordova.exec(Diagnostic._ensureBoolean(successCallback), 89 | errorCallback, 90 | 'Diagnostic_Motion', 91 | 'isMotionRequestOutcomeAvailable', 92 | []); 93 | }; 94 | 95 | /** 96 | * Requests motion tracking authorization for the application. 97 | * The native dialog asking user's consent can only be invoked once after the app is installed by calling this function. 98 | * Once the user has either allowed or denied access, calling this function again will result in an error. 99 | * It is not possible to re-invoke the dialog if the user denied permission in the native dialog, 100 | * so in this case you will have to instruct the user how to change motion authorization manually via the Settings app. 101 | * When calling this function, the message contained in the `NSMotionUsageDescription` .plist key is displayed to the user; 102 | * this plugin provides a default message, but you should override this with your specific reason for requesting access. 103 | * There's no direct way to determine if authorization was granted or denied, so the Pedometer API must be used to indirectly determine this: 104 | * therefore, if the device supports motion tracking but not Pedometer Event Tracking, the outcome of requesting motion detection cannot be determined. 105 | * 106 | * @param {Function} successCallback - The callback which will be called when operation is successful. 107 | * This callback function is passed a single string parameter indicating the result: 108 | * - `cordova.plugins.diagnostic.motionStatus.GRANTED` - user granted motion authorization. 109 | * - `cordova.plugins.diagnostic.motionStatus.DENIED_ALWAYS` - user denied authorization. 110 | * - `cordova.plugins.diagnostic.motionStatus.RESTRICTED` - user cannot grant motion authorization. 111 | * - `cordova.plugins.diagnostic.motionStatus.NOT_AVAILABLE` - device does not support Motion Tracking. 112 | * Motion tracking is supported by iOS devices with an M7 co-processor (or above): that is iPhone 5s (or above), iPad Air (or above), iPad Mini 2 (or above). 113 | * - `cordova.plugins.diagnostic.motionStatus.NOT_DETERMINED` - authorization outcome cannot be determined because device does not support Pedometer Event Tracking. 114 | * Pedometer Event Tracking is only available on iPhones with an M7 co-processor (or above): that is iPhone 5s (or above). No iPads yet support it. 115 | * - `cordova.plugins.diagnostic.motionStatus.UNKNOWN` - motion tracking authorization is in an unknown state. 116 | * - {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. 117 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 118 | * This callback function is passed a single string parameter containing the error message. 119 | */ 120 | Diagnostic_Motion.requestMotionAuthorization = function(successCallback, errorCallback) { 121 | return cordova.exec( 122 | successCallback, 123 | errorCallback, 124 | 'Diagnostic_Motion', 125 | 'requestMotionAuthorization', 126 | []); 127 | }; 128 | 129 | /** 130 | * Checks motion authorization status for the application. 131 | * There's no direct way to determine if authorization was granted or denied, so the Pedometer API is used to indirectly determine this. 132 | * Pedometer Event Tracking is only available on iPhones with an M7 co-processor (or above): that is iPhone 5s (or above). No iPads yet support it. 133 | * 134 | * @param {Function} successCallback - The callback which will be called when operation is successful. 135 | * This callback function is passed a single string parameter indicating the result: 136 | * - `cordova.plugins.diagnostic.motionStatus.NOT_REQUESTED` - App has not yet requested this permission. 137 | * - `cordova.plugins.diagnostic.motionStatus.GRANTED` - user granted motion authorization. 138 | * - `cordova.plugins.diagnostic.motionStatus.DENIED_ALWAYS` - user denied authorization. 139 | * - `cordova.plugins.diagnostic.motionStatus.RESTRICTED` - user cannot grant motion authorization. 140 | * - `cordova.plugins.diagnostic.motionStatus.NOT_AVAILABLE` - device does not support Motion Tracking. 141 | * Motion tracking is supported by iOS devices with an M7 co-processor (or above): that is iPhone 5s (or above), iPad Air (or above), iPad Mini 2 (or above). 142 | * - `cordova.plugins.diagnostic.motionStatus.NOT_DETERMINED` - authorization outcome cannot be determined because device does not support Pedometer Event Tracking. 143 | * Pedometer Event Tracking is only available on iPhones with an M7 co-processor (or above): that is iPhone 5s (or above). No iPads yet support it. 144 | * - `cordova.plugins.diagnostic.motionStatus.UNKNOWN` - motion tracking authorization is in an unknown state. 145 | * - {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. 146 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 147 | * This callback function is passed a single string parameter containing the error message. 148 | */ 149 | Diagnostic_Motion.getMotionAuthorizationStatus = function(successCallback, errorCallback) { 150 | return cordova.exec( 151 | successCallback, 152 | errorCallback, 153 | 'Diagnostic_Motion', 154 | 'getMotionAuthorizationStatus', 155 | []); 156 | }; 157 | 158 | return Diagnostic_Motion; 159 | }); 160 | module.exports = new Diagnostic_Motion(); 161 | -------------------------------------------------------------------------------- /www/ios/diagnostic.notifications.js: -------------------------------------------------------------------------------- 1 | /* globals cordova, require, exports, module */ 2 | 3 | /** 4 | * Diagnostic Notifications plugin for iOS 5 | * 6 | * Copyright (c) 2015 Working Edge Ltd. 7 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 8 | **/ 9 | var Diagnostic_Notifications = (function(){ 10 | /*********************** 11 | * 12 | * Internal properties 13 | * 14 | *********************/ 15 | var Diagnostic_Notifications = {}; 16 | 17 | var Diagnostic = require("cordova.plugins.diagnostic.Diagnostic"); 18 | 19 | /******************** 20 | * 21 | * Public properties 22 | * 23 | ********************/ 24 | 25 | Diagnostic.remoteNotificationType = Diagnostic_Notifications.remoteNotificationType = { 26 | ALERT: "alert", 27 | SOUND: "sound", 28 | BADGE: "badge" 29 | }; 30 | 31 | /******************** 32 | * 33 | * Internal functions 34 | * 35 | ********************/ 36 | 37 | /***************************** 38 | * 39 | * Protected member functions 40 | * 41 | ****************************/ 42 | 43 | 44 | /********************** 45 | * 46 | * Public API functions 47 | * 48 | **********************/ 49 | 50 | /** 51 | * Checks if remote (push) notifications are enabled. 52 | * 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"). 53 | * 54 | * @param {Function} successCallback - The callback which will be called when operation is successful. 55 | * This callback function is passed a single boolean parameter which is TRUE if remote (push) notifications are enabled. 56 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 57 | * This callback function is passed a single string parameter containing the error message. 58 | */ 59 | Diagnostic_Notifications.isRemoteNotificationsEnabled = function(successCallback, errorCallback) { 60 | return cordova.exec(Diagnostic._ensureBoolean(successCallback), 61 | errorCallback, 62 | 'Diagnostic_Notifications', 63 | 'isRemoteNotificationsEnabled', 64 | []); 65 | }; 66 | 67 | /** 68 | * Indicates the current setting of notification types for the app in the Settings app. 69 | * Note: if "Allow Notifications" switch is OFF, all types will be returned as disabled. 70 | * 71 | * @param {Function} successCallback - The callback which will be called when operation is successful. 72 | * 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: 73 | * cordova.plugins.diagnostic.remoteNotificationType.ALERT => alert style is not set to "None" (i.e. "Banners" or "Alerts"). 74 | * cordova.plugins.diagnostic.remoteNotificationType.BADGE => "Badge App Icon" switch is ON. 75 | * cordova.plugins.diagnostic.remoteNotificationType.SOUND => "Sounds"/"Alert Sound" switch is ON. 76 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 77 | * This callback function is passed a single string parameter containing the error message. 78 | */ 79 | Diagnostic_Notifications.getRemoteNotificationTypes = function(successCallback, errorCallback) { 80 | return cordova.exec(function(sTypes){ 81 | var oTypes = JSON.parse(sTypes); 82 | for(var type in oTypes){ 83 | oTypes[type] = parseInt(oTypes[type]) === 1 ; 84 | } 85 | successCallback(oTypes); 86 | }, 87 | errorCallback, 88 | 'Diagnostic_Notifications', 89 | 'getRemoteNotificationTypes', 90 | []); 91 | }; 92 | 93 | /** 94 | * Indicates if the app is registered for remote notifications on the device. 95 | * Returns true if the app is registered for remote notifications and received its device token, 96 | * or false if registration has not occurred, has failed, or has been denied by the user. 97 | * Note that user preferences for notifications in the Settings app will not affect this. 98 | * On iOS <=7, returns true if app is registered for remote notifications AND alert style is not set to "None" (i.e. "Banners" or "Alerts") - same as isRemoteNotificationsEnabled(). 99 | * 100 | * @param {Function} successCallback - The callback which will be called when operation is successful. 101 | * This callback function is passed a single boolean parameter which is TRUE if the device is registered for remote (push) notifications. 102 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 103 | * This callback function is passed a single string parameter containing the error message. 104 | */ 105 | Diagnostic_Notifications.isRegisteredForRemoteNotifications = function(successCallback, errorCallback) { 106 | return cordova.exec(Diagnostic._ensureBoolean(successCallback), 107 | errorCallback, 108 | 'Diagnostic_Notifications', 109 | 'isRegisteredForRemoteNotifications', 110 | []); 111 | }; 112 | 113 | /** 114 | * Returns the remote notifications authorization status for the application. 115 | * 116 | * @param {Object} params - (optional) parameters: 117 | * - {Function} successCallback - The callback which will be called when operation is successful. 118 | * This callback function is passed a single string parameter which indicates the authorization status as a constant in `cordova.plugins.diagnostic.permissionStatus`. 119 | * Possible values are: 120 | * `cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED` 121 | * `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS` 122 | * `cordova.plugins.diagnostic.permissionStatus.GRANTED` 123 | * - {Function} errorCallback - The callback which will be called when operation encounters an error. 124 | * This callback function is passed a single string parameter containing the error message. 125 | */ 126 | Diagnostic_Notifications.getRemoteNotificationsAuthorizationStatus = function() { 127 | var params; 128 | if (typeof arguments[0] === "function") { 129 | params = {}; 130 | params.successCallback = arguments[0]; 131 | if(typeof arguments[1] === "function") { 132 | params.errorCallback = arguments[1]; 133 | } 134 | }else{ 135 | params = arguments[0]; 136 | } 137 | 138 | return cordova.exec( 139 | params.successCallback, 140 | params.errorCallback, 141 | 'Diagnostic_Notifications', 142 | 'getRemoteNotificationsAuthorizationStatus', 143 | []); 144 | }; 145 | 146 | /** 147 | * Requests remote notifications authorization for the application. 148 | * 149 | * @param {Object} params - (optional) parameters: 150 | * - {Function} successCallback - The callback which will be called when operation is successful. 151 | * - {Function} errorCallback - The callback which will be called when operation encounters an error. 152 | * This callback function is passed a single string parameter containing the error message. 153 | * @param {Array} types - list of notifications to register for as constants in `cordova.plugins.diagnostic.remoteNotificationType`. 154 | * If not specified, defaults to all notification types. 155 | * @param {Boolean} omitRegistration - If true, registration for remote notifications will not be carried out once remote notifications authorization is granted. 156 | * Defaults to false (registration will automatically take place once authorization is granted). 157 | */ 158 | Diagnostic_Notifications.requestRemoteNotificationsAuthorization = function() { 159 | var params; 160 | if (typeof arguments[0] === "function") { 161 | params = {}; 162 | params.successCallback = arguments[0]; 163 | if(typeof arguments[1] === "function") { 164 | params.errorCallback = arguments[1]; 165 | } 166 | if(typeof arguments[2] !== "undefined") { 167 | params.types = arguments[2]; 168 | } 169 | if(typeof arguments[3] !== "undefined") { 170 | params.omitRegistration = arguments[3]; 171 | } 172 | }else{ 173 | params = arguments[0]; 174 | } 175 | 176 | params.types = params.types && params.types.length ? JSON.stringify(params.types) : JSON.stringify({}); 177 | 178 | return cordova.exec( 179 | params.successCallback, 180 | params.errorCallback, 181 | 'Diagnostic_Notifications', 182 | 'requestRemoteNotificationsAuthorization', 183 | [params.types, params.omitRegistration ? 1 : 0]); 184 | }; 185 | 186 | /** 187 | * Switches to the notifications page in the Settings app 188 | */ 189 | Diagnostic_Notifications.switchToNotificationSettings = function(successCallback, errorCallback) { 190 | return cordova.exec(successCallback, 191 | errorCallback, 192 | 'Diagnostic_Notifications', 193 | 'switchToNotificationSettings', 194 | []); 195 | }; 196 | 197 | 198 | return Diagnostic_Notifications; 199 | }); 200 | module.exports = new Diagnostic_Notifications(); 201 | -------------------------------------------------------------------------------- /www/ios/diagnostic.reminders.js: -------------------------------------------------------------------------------- 1 | /* globals cordova, require, exports, module */ 2 | 3 | /** 4 | * Diagnostic Reminders plugin for iOS 5 | * 6 | * Copyright (c) 2015 Working Edge Ltd. 7 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 8 | **/ 9 | var Diagnostic_Reminders = (function(){ 10 | /*********************** 11 | * 12 | * Internal properties 13 | * 14 | *********************/ 15 | var Diagnostic_Reminders = {}; 16 | 17 | var Diagnostic = require("cordova.plugins.diagnostic.Diagnostic"); 18 | 19 | /******************** 20 | * 21 | * Public properties 22 | * 23 | ********************/ 24 | 25 | /******************** 26 | * 27 | * Internal functions 28 | * 29 | ********************/ 30 | 31 | /***************************** 32 | * 33 | * Protected member functions 34 | * 35 | ****************************/ 36 | 37 | 38 | /********************** 39 | * 40 | * Public API functions 41 | * 42 | **********************/ 43 | /** 44 | * Checks if the application is authorized to use calendar reminders. 45 | * 46 | * @param {Function} successCallback - The callback which will be called when operation is successful. 47 | * This callback function is passed a single boolean parameter which is TRUE if reminders is authorized for use. 48 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 49 | * This callback function is passed a single string parameter containing the error message. 50 | */ 51 | Diagnostic_Reminders.isRemindersAuthorized = function(successCallback, errorCallback) { 52 | return cordova.exec(Diagnostic._ensureBoolean(successCallback), 53 | errorCallback, 54 | 'Diagnostic_Reminders', 55 | 'isRemindersAuthorized', 56 | []); 57 | }; 58 | 59 | /** 60 | * Returns the calendar event authorization status for the application. 61 | * 62 | * @param {Function} successCallback - The callback which will be called when operation is successful. 63 | * This callback function is passed a single string parameter which indicates the authorization status as a constant in `cordova.plugins.diagnostic.permissionStatus`. 64 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 65 | * This callback function is passed a single string parameter containing the error message. 66 | */ 67 | Diagnostic_Reminders.getRemindersAuthorizationStatus = function(successCallback, errorCallback) { 68 | return cordova.exec(successCallback, 69 | errorCallback, 70 | 'Diagnostic_Reminders', 71 | 'getRemindersAuthorizationStatus', 72 | []); 73 | }; 74 | 75 | /** 76 | * Requests calendar reminders authorization for the application. 77 | * Should only be called if authorization status is NOT_REQUESTED. Calling it when in any other state will have no effect. 78 | * 79 | * @param {Function} successCallback - The callback which will be called when operation is successful. 80 | * This callback function is passed a single string parameter indicating whether access to reminders was granted or denied: 81 | * `cordova.plugins.diagnostic.permissionStatus.GRANTED` or `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS` 82 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 83 | * This callback function is passed a single string parameter containing the error message. 84 | */ 85 | Diagnostic_Reminders.requestRemindersAuthorization = function(successCallback, errorCallback) { 86 | return cordova.exec(function(isGranted){ 87 | successCallback(isGranted ? Diagnostic.permissionStatus.GRANTED : Diagnostic.permissionStatus.DENIED_ALWAYS); 88 | }, 89 | errorCallback, 90 | 'Diagnostic_Reminders', 91 | 'requestRemindersAuthorization', 92 | []); 93 | }; 94 | 95 | return Diagnostic_Reminders; 96 | }); 97 | module.exports = new Diagnostic_Reminders(); 98 | -------------------------------------------------------------------------------- /www/ios/diagnostic.wifi.js: -------------------------------------------------------------------------------- 1 | /* globals cordova, require, exports, module */ 2 | 3 | /** 4 | * Diagnostic Wifi plugin for iOS 5 | * 6 | * Copyright (c) 2015 Working Edge Ltd. 7 | * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS 8 | **/ 9 | var Diagnostic_Wifi = (function(){ 10 | /*********************** 11 | * 12 | * Internal properties 13 | * 14 | *********************/ 15 | var Diagnostic_Wifi = {}; 16 | 17 | var Diagnostic = require("cordova.plugins.diagnostic.Diagnostic"); 18 | 19 | /******************** 20 | * 21 | * Public properties 22 | * 23 | ********************/ 24 | 25 | /******************** 26 | * 27 | * Internal functions 28 | * 29 | ********************/ 30 | 31 | /***************************** 32 | * 33 | * Protected member functions 34 | * 35 | ****************************/ 36 | 37 | 38 | /********************** 39 | * 40 | * Public API functions 41 | * 42 | **********************/ 43 | 44 | /** 45 | * Checks if Wi-Fi is connected. 46 | * On iOS this returns true if the WiFi setting is set to enabled AND the device is connected to a network by WiFi. 47 | * 48 | * @param {Function} successCallback - The callback which will be called when operation is successful. 49 | * This callback function is passed a single boolean parameter which is TRUE if device is connected by WiFi. 50 | * @param {Function} errorCallback - The callback which will be called when operation encounters an error. 51 | * This callback function is passed a single string parameter containing the error message. 52 | */ 53 | Diagnostic_Wifi.isWifiAvailable = function(successCallback, errorCallback) { 54 | return cordova.exec(Diagnostic._ensureBoolean(successCallback), 55 | errorCallback, 56 | 'Diagnostic_Wifi', 57 | 'isWifiAvailable', 58 | []); 59 | }; 60 | 61 | /** 62 | * Checks if Wifi is enabled. 63 | * On iOS this returns true if the WiFi setting is set to enabled (regardless of whether it's connected to a network). 64 | * 65 | * @param {Function} successCallback - The callback which will be called when the operation is successful. 66 | * This callback function is passed a single boolean parameter which is TRUE if WiFi is enabled. 67 | * @param {Function} errorCallback - The callback which will be called when the operation encounters an error. 68 | * This callback function is passed a single string parameter containing the error message. 69 | */ 70 | Diagnostic_Wifi.isWifiEnabled = function(successCallback, errorCallback) { 71 | return cordova.exec(successCallback, 72 | errorCallback, 73 | 'Diagnostic_Wifi', 74 | 'isWifiEnabled', 75 | []); 76 | }; 77 | 78 | return Diagnostic_Wifi; 79 | }); 80 | module.exports = new Diagnostic_Wifi(); --------------------------------------------------------------------------------