Files
RandyMcMillan a12110e6fa .
2012-05-05 16:38:16 -04:00
..
.
2012-05-05 16:38:16 -04:00
.
2012-05-05 16:38:16 -04:00
2012-05-04 11:43:37 +01:00

Diagnostic plugin for PhoneGap

The diagnostic plugin allows you to check different device settings in your PhoneGap application.

A simple use case would be:

  • Your app require geolocation and you want check if the location services are enabled in device settings.
  • Your app require the Wi-Fi enabled for the wireless network location and you want check if the Wi-Fi is enabled in device settings.
  • Your app require the camera enabled and you want check if the camera is enabled in device settings.

Adding the Plugin to your project

Using this plugin requires a PhoneGap project for iOS: Get Started Guide.

  1. To install the plugin, move diagnostic.js to your project's www folder and include a reference to it in your html file after cordova.js:

      <script type="text/javascript" charset="utf-8" src="cordova-X.X.X.js"></script>
      <script type="text/javascript" charset="utf-8" src="diagnostic.js"></script>
     
  2. Move Diagnostic.h and Diagnostic.m files into Plugins folder.

  3. And edit Cordova.plist creating a new entry in the Plugins section as follows:

         - Key:    Diagnostic
         - Type:   String
         - Value:  Diagnostic
     

Using the plugin

The plugin creates the object:

 window.plugins.diagnostic

To use, call one of the following, available methods:

  • isLocationEnabled:
/**
 * Checks if location is enabled (Device setting for location and authorization).
 *
 * @param successCallback	The callback which will be called when diagnostic of location is successful.
 * 							This callback function have a boolean param with the diagnostic result.
 * @param errorCallback		The callback which will be called when diagnostic of location encounters an error.
 * 							This callback function have a string param with the error.
 */
isLocationEnabled()

Usage:

   window.plugins.diagnostic.isLocationEnabled(locationEnabledSuccessCallback, locationEnabledErrorCallback);

   function locationEnabledSuccessCallback(result) {
      if (result)
         alert("Location ON");
      else
         alert("Location OFF");
   }

   function locationEnabledErrorCallback(error) {
      console.log(error);
   }
  • isLocationEnabledSetting:
/**
 * Checks device settings for location.
 *
 * @param successCallback	The callback which will be called when diagnostic of location is successful.
 * 							This callback function have a boolean param with the diagnostic result.
 * @param errorCallback		The callback which will be called when diagnostic of location encounters an error.
 * 							This callback function have a string param with the error.
 */
isLocationEnabledSetting()

Usage:

   window.plugins.diagnostic.isLocationEnabledSetting(locationEnabledSettingSuccessCallback, locationEnabledSettingErrorCallback);

   function locationEnabledSettingSuccessCallback(result) {
      if (result)
         alert("Location ON");
      else
         alert("Location OFF");
   }

   function locationEnabledSettingErrorCallback(error) {
      console.log(error);
   }
  • isLocationAuthorized:
/**
 * Checks if the application is authorized to use location.
 *
 * @param successCallback	The callback which will be called when diagnostic of location is successful.
 * 							This callback function have a boolean param with the diagnostic result.
 * @param errorCallback		The callback which will be called when diagnostic of location encounters an error.
 * 							This callback function have a string param with the error.
 */
isLocationAuthorized()

Usage:

   window.plugins.diagnostic.isLocationAuthorized(locationAuthorizedSuccessCallback, locationAuthorizedErrorCallback);

   function locationAuthorizedSuccessCallback(result) {
      if (result)
         alert("Authorized to use location");
      else
         alert("Not authorized to use location");
   }

   function locationAuthorizedErrorCallback(error) {
      console.log(error);
   }
  • isWifiEnabled:
/**
 * Checks if exists Wi-Fi connection.
 *
 * @param successCallback	The callback which will be called when diagnostic of Wi-Fi is successful.
 * 							This callback function have a boolean param with the diagnostic result.
 * @param errorCallback		The callback which will be called when diagnostic of Wi-Fi encounters an error.
 * 							This callback function have a string param with the error.
 */
isWifiEnabled()

Usage:

   window.plugins.diagnostic.isWifiEnabled(wifiEnabledSuccessCallback, wifiEnabledErrorCallback);

   function wifiEnabledSuccessCallback(result) {
	   if (result)
	      alert("Wi-Fi ON");
	   else
	      alert("Wi-Fi OFF");
   }

   function wifiEnabledErrorCallback(error) {
	   console.log(error);
  }
  • isCameraEnabled:
/**
 * Checks if exists camera.
 *
 * @param successCallback	The callback which will be called when diagnostic of camera is successful.
 * 							This callback function have a boolean param with the diagnostic result.
 * @param errorCallback		The callback which will be called when diagnostic of camera encounters an error.
 * 							This callback function have a string param with the error.
 */
isCameraEnabled()

Usage:

   window.plugins.diagnostic.isCameraEnabled(cameraEnabledSuccessCallback, cameraEnabledErrorCallback);

   function cameraEnabledSuccessCallback(result) {
	  if (result)
	     alert("Camera ON");
	  else
	     alert("Camera OFF");
   }

   function cameraEnabledErrorCallback(error) {
	  console.log(error);
   }

LICENSE

Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS

The MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.