cordova.plugins.diagnostic 7.2.9 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +567 -456
- package/cordova.plugins.diagnostic.d.ts +65 -1
- package/package.json +1 -1
- package/plugin.xml +1 -1
- package/src/android/Diagnostic.java +78 -0
- package/src/ios/Diagnostic.h +2 -0
- package/src/ios/Diagnostic.m +26 -0
- package/src/ios/Diagnostic_Bluetooth.m +3 -1
- package/src/ios/Diagnostic_Location.m +35 -0
- package/www/android/diagnostic.js +59 -1
- package/www/ios/diagnostic.js +38 -2
- package/www/ios/diagnostic.location.js +19 -3
- package/.specstory/.project.json +0 -8
|
@@ -110,8 +110,22 @@ interface Diagnostic {
|
|
|
110
110
|
* @type {Object}
|
|
111
111
|
*/
|
|
112
112
|
locationAccuracyAuthorization: {
|
|
113
|
+
/** Alias for BEST. Sets kCLLocationAccuracyBest on iOS. */
|
|
113
114
|
"FULL": "full";
|
|
115
|
+
/** Sets kCLLocationAccuracyReduced on iOS - approximate location, no GPS. */
|
|
114
116
|
"REDUCED": "reduced";
|
|
117
|
+
/** Sets kCLLocationAccuracyBest on iOS - may engage GPS hardware. */
|
|
118
|
+
"BEST": "best";
|
|
119
|
+
/** Sets kCLLocationAccuracyBestForNavigation on iOS - highest accuracy with additional sensors. */
|
|
120
|
+
"BEST_FOR_NAVIGATION": "bestForNavigation";
|
|
121
|
+
/** Sets kCLLocationAccuracyNearestTenMeters on iOS. */
|
|
122
|
+
"NEAREST_TEN_METERS": "nearestTenMeters";
|
|
123
|
+
/** Sets kCLLocationAccuracyHundredMeters on iOS. */
|
|
124
|
+
"HUNDRED_METERS": "hundredMeters";
|
|
125
|
+
/** Sets kCLLocationAccuracyKilometer on iOS. */
|
|
126
|
+
"KILOMETER": "kilometer";
|
|
127
|
+
/** Sets kCLLocationAccuracyThreeKilometers on iOS. */
|
|
128
|
+
"THREE_KILOMETERS": "threeKilometers";
|
|
115
129
|
};
|
|
116
130
|
|
|
117
131
|
|
|
@@ -464,7 +478,17 @@ interface Diagnostic {
|
|
|
464
478
|
* @param successCallback
|
|
465
479
|
* @param errorCallback
|
|
466
480
|
* @param mode - (optional / iOS & Android >= 10) location authorization mode specified as a locationAuthorizationMode constant. If not specified, defaults to WHEN_IN_USE.
|
|
467
|
-
* @param accuracy
|
|
481
|
+
* @param accuracy - (optional / iOS & Android 12+) desired location accuracy as a locationAccuracyAuthorization constant.
|
|
482
|
+
* If not specified, defaults to FULL.
|
|
483
|
+
* On iOS, this sets the CLLocationManager's desiredAccuracy:
|
|
484
|
+
* - FULL / BEST - kCLLocationAccuracyBest (may engage GPS hardware)
|
|
485
|
+
* - REDUCED - kCLLocationAccuracyReduced (approximate location, no GPS)
|
|
486
|
+
* - BEST_FOR_NAVIGATION - kCLLocationAccuracyBestForNavigation
|
|
487
|
+
* - NEAREST_TEN_METERS - kCLLocationAccuracyNearestTenMeters
|
|
488
|
+
* - HUNDRED_METERS - kCLLocationAccuracyHundredMeters
|
|
489
|
+
* - KILOMETER - kCLLocationAccuracyKilometer
|
|
490
|
+
* - THREE_KILOMETERS - kCLLocationAccuracyThreeKilometers
|
|
491
|
+
* On Android < 12, has no effect.
|
|
468
492
|
*/
|
|
469
493
|
requestLocationAuthorization?: (
|
|
470
494
|
successCallback: (status: string) => void,
|
|
@@ -717,6 +741,46 @@ interface Diagnostic {
|
|
|
717
741
|
errorCallback: (error: string) => void
|
|
718
742
|
) => void;
|
|
719
743
|
|
|
744
|
+
/**
|
|
745
|
+
* Checks if low power mode is currently enabled on the device.
|
|
746
|
+
* @param successCallback
|
|
747
|
+
* @param errorCallback
|
|
748
|
+
*/
|
|
749
|
+
isLowPowerModeEnabled?: (
|
|
750
|
+
successCallback: (enabled: boolean) => void,
|
|
751
|
+
errorCallback: (error: string) => void
|
|
752
|
+
) => void;
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* Registers a function to be called when low power mode changes.
|
|
756
|
+
* @param successCallback
|
|
757
|
+
*/
|
|
758
|
+
onLowPowerModeChange?: (
|
|
759
|
+
successCallback: (enabled: boolean) => void
|
|
760
|
+
) => void;
|
|
761
|
+
|
|
762
|
+
/**
|
|
763
|
+
* ANDROID ONLY
|
|
764
|
+
* Checks if the app is currently ignoring battery optimizations.
|
|
765
|
+
* @param successCallback
|
|
766
|
+
* @param errorCallback
|
|
767
|
+
*/
|
|
768
|
+
isIgnoringBatteryOptimizations?: (
|
|
769
|
+
successCallback: (enabled: boolean) => void,
|
|
770
|
+
errorCallback: (error: string) => void
|
|
771
|
+
) => void;
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* ANDROID ONLY
|
|
775
|
+
* Prompts the user to allow the app to ignore battery optimizations.
|
|
776
|
+
* @param successCallback
|
|
777
|
+
* @param errorCallback
|
|
778
|
+
*/
|
|
779
|
+
requestIgnoreBatteryOptimizations?: (
|
|
780
|
+
successCallback: () => void,
|
|
781
|
+
errorCallback: (error: string) => void
|
|
782
|
+
) => void;
|
|
783
|
+
|
|
720
784
|
/**
|
|
721
785
|
* ANDROID ONLY
|
|
722
786
|
* Checks if high-accuracy locations are available to the app from GPS hardware.
|
package/package.json
CHANGED
package/plugin.xml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
|
|
3
3
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
4
4
|
id="cordova.plugins.diagnostic"
|
|
5
|
-
version="7.
|
|
5
|
+
version="7.3.0">
|
|
6
6
|
|
|
7
7
|
<name>Diagnostic</name>
|
|
8
8
|
<description>Cordova/Phonegap plugin to check the state of Location/WiFi/Camera/Bluetooth device settings.</description>
|
|
@@ -46,13 +46,16 @@ import android.Manifest;
|
|
|
46
46
|
import android.app.Activity;
|
|
47
47
|
import android.app.AlarmManager;
|
|
48
48
|
import android.app.PendingIntent;
|
|
49
|
+
import android.content.BroadcastReceiver;
|
|
49
50
|
import android.content.SharedPreferences;
|
|
51
|
+
import android.content.IntentFilter;
|
|
50
52
|
import android.content.pm.ApplicationInfo;
|
|
51
53
|
import android.content.pm.PackageInfo;
|
|
52
54
|
import android.net.ConnectivityManager;
|
|
53
55
|
import android.net.Uri;
|
|
54
56
|
import android.os.BatteryManager;
|
|
55
57
|
import android.os.Build;
|
|
58
|
+
import android.os.PowerManager;
|
|
56
59
|
import android.util.Log;
|
|
57
60
|
|
|
58
61
|
import android.content.Context;
|
|
@@ -263,6 +266,7 @@ public class Diagnostic extends CordovaPlugin{
|
|
|
263
266
|
|
|
264
267
|
protected SharedPreferences sharedPref;
|
|
265
268
|
protected SharedPreferences.Editor editor;
|
|
269
|
+
protected boolean currentLowPowerModeEnabled = false;
|
|
266
270
|
|
|
267
271
|
/*************
|
|
268
272
|
* Public API
|
|
@@ -291,10 +295,31 @@ public class Diagnostic extends CordovaPlugin{
|
|
|
291
295
|
applicationContext = this.cordova.getActivity().getApplicationContext();
|
|
292
296
|
sharedPref = cordova.getActivity().getSharedPreferences(TAG, Activity.MODE_PRIVATE);
|
|
293
297
|
editor = sharedPref.edit();
|
|
298
|
+
currentLowPowerModeEnabled = isLowPowerModeEnabled();
|
|
299
|
+
|
|
300
|
+
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
|
|
301
|
+
try {
|
|
302
|
+
applicationContext.registerReceiver(lowPowerModeChangedReceiver, new IntentFilter(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED));
|
|
303
|
+
} catch (Exception e) {
|
|
304
|
+
logWarning("Unable to register low power mode change receiver: " + e.getMessage());
|
|
305
|
+
}
|
|
306
|
+
}
|
|
294
307
|
|
|
295
308
|
super.initialize(cordova, webView);
|
|
296
309
|
}
|
|
297
310
|
|
|
311
|
+
@Override
|
|
312
|
+
public void onDestroy() {
|
|
313
|
+
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
|
|
314
|
+
try {
|
|
315
|
+
applicationContext.unregisterReceiver(lowPowerModeChangedReceiver);
|
|
316
|
+
} catch (Exception e) {
|
|
317
|
+
logWarning("Unable to unregister low power mode change receiver: " + e.getMessage());
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
super.onDestroy();
|
|
321
|
+
}
|
|
322
|
+
|
|
298
323
|
/**
|
|
299
324
|
* Executes the request and returns PluginResult.
|
|
300
325
|
*
|
|
@@ -351,6 +376,13 @@ public class Diagnostic extends CordovaPlugin{
|
|
|
351
376
|
callbackContext.success(getCPUArchitecture());
|
|
352
377
|
} else if(action.equals("getCurrentBatteryLevel")) {
|
|
353
378
|
callbackContext.success(getCurrentBatteryLevel());
|
|
379
|
+
} else if(action.equals("isLowPowerModeEnabled")) {
|
|
380
|
+
callbackContext.success(isLowPowerModeEnabled() ? 1 : 0);
|
|
381
|
+
} else if(action.equals("isIgnoringBatteryOptimizations")) {
|
|
382
|
+
callbackContext.success(isIgnoringBatteryOptimizations() ? 1 : 0);
|
|
383
|
+
} else if(action.equals("requestIgnoreBatteryOptimizations")) {
|
|
384
|
+
requestIgnoreBatteryOptimizations();
|
|
385
|
+
callbackContext.success();
|
|
354
386
|
} else if(action.equals("isAirplaneModeEnabled")) {
|
|
355
387
|
callbackContext.success(isAirplaneModeEnabled() ? 1 : 0);
|
|
356
388
|
} else if(action.equals("getDeviceOSVersion")) {
|
|
@@ -861,6 +893,17 @@ public class Diagnostic extends CordovaPlugin{
|
|
|
861
893
|
executeGlobalJavascript("cordova.plugins.diagnostic." + jsString);
|
|
862
894
|
}
|
|
863
895
|
|
|
896
|
+
protected final BroadcastReceiver lowPowerModeChangedReceiver = new BroadcastReceiver() {
|
|
897
|
+
@Override
|
|
898
|
+
public void onReceive(Context context, Intent intent) {
|
|
899
|
+
final String action = intent.getAction();
|
|
900
|
+
if(instance != null && PowerManager.ACTION_POWER_SAVE_MODE_CHANGED.equals(action)){
|
|
901
|
+
Log.v(TAG, "lowPowerModeChangedReceiver");
|
|
902
|
+
instance.notifyLowPowerModeChange();
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
};
|
|
906
|
+
|
|
864
907
|
/**
|
|
865
908
|
* Performs a warm app restart - restarts only Cordova main activity
|
|
866
909
|
*/
|
|
@@ -953,6 +996,41 @@ public class Diagnostic extends CordovaPlugin{
|
|
|
953
996
|
return bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
|
|
954
997
|
}
|
|
955
998
|
|
|
999
|
+
protected boolean isLowPowerModeEnabled(){
|
|
1000
|
+
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP){
|
|
1001
|
+
return false;
|
|
1002
|
+
}
|
|
1003
|
+
PowerManager powerManager = (PowerManager) cordova.getContext().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
|
1004
|
+
return powerManager != null && powerManager.isPowerSaveMode();
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
protected boolean isIgnoringBatteryOptimizations(){
|
|
1008
|
+
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M){
|
|
1009
|
+
return true;
|
|
1010
|
+
}
|
|
1011
|
+
PowerManager powerManager = (PowerManager) cordova.getContext().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
|
1012
|
+
return powerManager != null && powerManager.isIgnoringBatteryOptimizations(cordova.getActivity().getPackageName());
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
protected void requestIgnoreBatteryOptimizations(){
|
|
1016
|
+
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M || isIgnoringBatteryOptimizations()){
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
|
1021
|
+
intent.setData(Uri.parse("package:" + cordova.getActivity().getPackageName()));
|
|
1022
|
+
cordova.getActivity().startActivity(intent);
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
protected void notifyLowPowerModeChange(){
|
|
1026
|
+
boolean lowPowerModeEnabled = isLowPowerModeEnabled();
|
|
1027
|
+
if(lowPowerModeEnabled != currentLowPowerModeEnabled){
|
|
1028
|
+
currentLowPowerModeEnabled = lowPowerModeEnabled;
|
|
1029
|
+
logDebug("Low power mode changed to: " + lowPowerModeEnabled);
|
|
1030
|
+
executePluginJavascript("_onLowPowerModeChange(" + (lowPowerModeEnabled ? "true" : "false") + ");");
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
|
|
956
1034
|
// https://stackoverflow.com/a/18237962/777265
|
|
957
1035
|
protected boolean hasBuildPermission(String permission)
|
|
958
1036
|
{
|
package/src/ios/Diagnostic.h
CHANGED
|
@@ -28,6 +28,7 @@ extern NSString*const AUTHORIZATION_LIMITED;
|
|
|
28
28
|
|
|
29
29
|
@property (nonatomic) float osVersion;
|
|
30
30
|
@property (nonatomic) BOOL debugEnabled;
|
|
31
|
+
@property (nonatomic, strong) id lowPowerModeChangeObserver;
|
|
31
32
|
|
|
32
33
|
// Plugin API
|
|
33
34
|
- (void) enableDebug: (CDVInvokedUrlCommand*)command;
|
|
@@ -35,6 +36,7 @@ extern NSString*const AUTHORIZATION_LIMITED;
|
|
|
35
36
|
- (void) getBackgroundRefreshStatus: (CDVInvokedUrlCommand*)command;
|
|
36
37
|
- (void) getArchitecture: (CDVInvokedUrlCommand*)command;
|
|
37
38
|
- (void) getCurrentBatteryLevel: (CDVInvokedUrlCommand*)command;
|
|
39
|
+
- (void) isLowPowerModeEnabled: (CDVInvokedUrlCommand*)command;
|
|
38
40
|
- (void) getDeviceOSVersion: (CDVInvokedUrlCommand*)command;
|
|
39
41
|
- (void) getBuildOSVersion: (CDVInvokedUrlCommand*)command;
|
|
40
42
|
- (void) isMobileDataAuthorized: (CDVInvokedUrlCommand*)command;
|
package/src/ios/Diagnostic.m
CHANGED
|
@@ -41,6 +41,7 @@ static Diagnostic* diagnostic = nil;
|
|
|
41
41
|
static CTCellularData* cellularData;
|
|
42
42
|
#endif
|
|
43
43
|
|
|
44
|
+
|
|
44
45
|
/********************************/
|
|
45
46
|
#pragma mark - Public static functions
|
|
46
47
|
/********************************/
|
|
@@ -126,6 +127,12 @@ static CTCellularData* cellularData;
|
|
|
126
127
|
#if !TARGET_OS_MACCATALYST
|
|
127
128
|
cellularData = [[CTCellularData alloc] init];
|
|
128
129
|
#endif
|
|
130
|
+
|
|
131
|
+
self.lowPowerModeChangeObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSProcessInfoPowerStateDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
|
|
132
|
+
BOOL isLowPowerModeEnabled = [[NSProcessInfo processInfo] isLowPowerModeEnabled];
|
|
133
|
+
[self logDebug:[NSString stringWithFormat:@"Low power mode changed to: %@", isLowPowerModeEnabled ? @"true" : @"false"]];
|
|
134
|
+
[self executeGlobalJavascript:[NSString stringWithFormat:@"cordova.plugins.diagnostic._onLowPowerModeChange(%@);", isLowPowerModeEnabled ? @"true" : @"false"]];
|
|
135
|
+
}];
|
|
129
136
|
}
|
|
130
137
|
|
|
131
138
|
// https://stackoverflow.com/a/38441011/777265
|
|
@@ -186,6 +193,18 @@ static CTCellularData* cellularData;
|
|
|
186
193
|
}];
|
|
187
194
|
}
|
|
188
195
|
|
|
196
|
+
- (void) isLowPowerModeEnabled: (CDVInvokedUrlCommand*)command {
|
|
197
|
+
[self.commandDelegate runInBackground:^{
|
|
198
|
+
@try {
|
|
199
|
+
BOOL isLowPowerModeEnabled = [[NSProcessInfo processInfo] isLowPowerModeEnabled];
|
|
200
|
+
[self logDebug:[NSString stringWithFormat:@"Low power mode enabled: %@", isLowPowerModeEnabled ? @"true" : @"false"]];
|
|
201
|
+
[self sendPluginResultBool:isLowPowerModeEnabled :command];
|
|
202
|
+
}@catch (NSException *exception) {
|
|
203
|
+
[self handlePluginException:exception :command];
|
|
204
|
+
}
|
|
205
|
+
}];
|
|
206
|
+
}
|
|
207
|
+
|
|
189
208
|
- (void) getDeviceOSVersion: (CDVInvokedUrlCommand*)command {
|
|
190
209
|
[self.commandDelegate runInBackground:^{
|
|
191
210
|
@try {
|
|
@@ -419,6 +438,13 @@ static CTCellularData* cellularData;
|
|
|
419
438
|
return [[NSUserDefaults standardUserDefaults] objectForKey:key];
|
|
420
439
|
}
|
|
421
440
|
|
|
441
|
+
- (void)dealloc {
|
|
442
|
+
if(self.lowPowerModeChangeObserver != nil){
|
|
443
|
+
[[NSNotificationCenter defaultCenter] removeObserver:self.lowPowerModeChangeObserver];
|
|
444
|
+
self.lowPowerModeChangeObserver = nil;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
422
448
|
@end
|
|
423
449
|
|
|
424
450
|
|
|
@@ -156,12 +156,14 @@ static NSString*const LOG_TAG = @"Diagnostic_Bluetooth[native]";
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
- (void) ensureBluetoothManager {
|
|
159
|
-
|
|
159
|
+
@synchronized(self) {
|
|
160
|
+
if(![self.bluetoothManager isKindOfClass:[CBCentralManager class]]){
|
|
160
161
|
self.bluetoothManager = [[CBCentralManager alloc]
|
|
161
162
|
initWithDelegate:self
|
|
162
163
|
queue:dispatch_get_main_queue()
|
|
163
164
|
options:@{CBCentralManagerOptionShowPowerAlertKey: @(NO)}];
|
|
164
165
|
[self centralManagerDidUpdateState:self.bluetoothManager]; // Send initial state
|
|
166
|
+
}
|
|
165
167
|
}
|
|
166
168
|
}
|
|
167
169
|
|
|
@@ -78,6 +78,41 @@ static NSString*const LOG_TAG = @"Diagnostic_Location[native]";
|
|
|
78
78
|
@try {
|
|
79
79
|
if ([CLLocationManager instancesRespondToSelector:@selector(requestWhenInUseAuthorization)])
|
|
80
80
|
{
|
|
81
|
+
// Apply desired accuracy if specified (argument at index 1).
|
|
82
|
+
// Maps string values to CLLocationAccuracy constants.
|
|
83
|
+
// If not specified or unrecognised, defaults to kCLLocationAccuracyBest to maintain backward
|
|
84
|
+
// compatibility. Apps that do not require precise location (e.g. only need the Wi-Fi SSID)
|
|
85
|
+
// should pass "reduced" to avoid engaging GPS hardware and unnecessary battery drain.
|
|
86
|
+
NSString* accuracy = [command argumentAtIndex:1 withDefault:nil];
|
|
87
|
+
if(accuracy != nil){
|
|
88
|
+
if([accuracy isEqualToString:@"reduced"]){
|
|
89
|
+
self.locationManager.desiredAccuracy = kCLLocationAccuracyReduced;
|
|
90
|
+
[diagnostic logDebug:@"Setting location accuracy: reduced"];
|
|
91
|
+
}else if([accuracy isEqualToString:@"bestForNavigation"]){
|
|
92
|
+
self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
|
|
93
|
+
[diagnostic logDebug:@"Setting location accuracy: bestForNavigation"];
|
|
94
|
+
}else if([accuracy isEqualToString:@"nearestTenMeters"]){
|
|
95
|
+
self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
|
|
96
|
+
[diagnostic logDebug:@"Setting location accuracy: nearestTenMeters"];
|
|
97
|
+
}else if([accuracy isEqualToString:@"hundredMeters"]){
|
|
98
|
+
self.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
|
|
99
|
+
[diagnostic logDebug:@"Setting location accuracy: hundredMeters"];
|
|
100
|
+
}else if([accuracy isEqualToString:@"kilometer"]){
|
|
101
|
+
self.locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
|
|
102
|
+
[diagnostic logDebug:@"Setting location accuracy: kilometer"];
|
|
103
|
+
}else if([accuracy isEqualToString:@"threeKilometers"]){
|
|
104
|
+
self.locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
|
|
105
|
+
[diagnostic logDebug:@"Setting location accuracy: threeKilometers"];
|
|
106
|
+
}else{
|
|
107
|
+
// "full", "best", or any unrecognised value
|
|
108
|
+
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
|
|
109
|
+
[diagnostic logDebug:@"Setting location accuracy: best"];
|
|
110
|
+
}
|
|
111
|
+
}else{
|
|
112
|
+
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
|
|
113
|
+
[diagnostic logDebug:@"Setting location accuracy: best (default)"];
|
|
114
|
+
}
|
|
115
|
+
|
|
81
116
|
BOOL always = [[command argumentAtIndex:0] boolValue];
|
|
82
117
|
if(always){
|
|
83
118
|
NSAssert([[[NSBundle mainBundle] infoDictionary] valueForKey:@"NSLocationAlwaysAndWhenInUseUsageDescription"], @"Your app must have a value for NSLocationAlwaysAndWhenInUseUsageDescription in its Info.plist");
|
|
@@ -112,7 +112,8 @@ var Diagnostic = (function(){
|
|
|
112
112
|
*
|
|
113
113
|
****************************/
|
|
114
114
|
// Placeholder listeners
|
|
115
|
-
Diagnostic.
|
|
115
|
+
Diagnostic._onLowPowerModeChange =
|
|
116
|
+
Diagnostic._onNFCStateChange =
|
|
116
117
|
Diagnostic._onPermissionRequestComplete = function(){};
|
|
117
118
|
|
|
118
119
|
Diagnostic._combinePermissionStatuses = function(statuses){
|
|
@@ -484,6 +485,63 @@ var Diagnostic = (function(){
|
|
|
484
485
|
[]);
|
|
485
486
|
};
|
|
486
487
|
|
|
488
|
+
/**
|
|
489
|
+
* Checks if low power mode is currently enabled on device.
|
|
490
|
+
*
|
|
491
|
+
* @param {Function} successCallback - The callback which will be called when the operation is successful.
|
|
492
|
+
* This callback function is passed a single boolean parameter which is TRUE if low power mode is enabled.
|
|
493
|
+
* @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
|
|
494
|
+
* This callback function is passed a single string parameter containing the error message.
|
|
495
|
+
*/
|
|
496
|
+
Diagnostic.isLowPowerModeEnabled = function(successCallback, errorCallback){
|
|
497
|
+
return cordova.exec(Diagnostic._ensureBoolean(successCallback),
|
|
498
|
+
errorCallback,
|
|
499
|
+
'Diagnostic',
|
|
500
|
+
'isLowPowerModeEnabled',
|
|
501
|
+
[]);
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Checks if the app is currently ignoring battery optimizations.
|
|
506
|
+
*
|
|
507
|
+
* @param {Function} successCallback - The callback which will be called when the operation is successful.
|
|
508
|
+
* This callback function is passed a single boolean parameter which is TRUE if the app is ignoring battery optimizations.
|
|
509
|
+
* @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
|
|
510
|
+
* This callback function is passed a single string parameter containing the error message.
|
|
511
|
+
*/
|
|
512
|
+
Diagnostic.isIgnoringBatteryOptimizations = function(successCallback, errorCallback){
|
|
513
|
+
return cordova.exec(Diagnostic._ensureBoolean(successCallback),
|
|
514
|
+
errorCallback,
|
|
515
|
+
'Diagnostic',
|
|
516
|
+
'isIgnoringBatteryOptimizations',
|
|
517
|
+
[]);
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* Prompts the user to allow the app to ignore battery optimizations.
|
|
522
|
+
*
|
|
523
|
+
* @param {Function} successCallback - The callback which will be called when the request intent is opened.
|
|
524
|
+
* @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
|
|
525
|
+
* This callback function is passed a single string parameter containing the error message.
|
|
526
|
+
*/
|
|
527
|
+
Diagnostic.requestIgnoreBatteryOptimizations = function(successCallback, errorCallback){
|
|
528
|
+
return cordova.exec(successCallback,
|
|
529
|
+
errorCallback,
|
|
530
|
+
'Diagnostic',
|
|
531
|
+
'requestIgnoreBatteryOptimizations',
|
|
532
|
+
[]);
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Registers a function to be called when the device low power mode changes.
|
|
537
|
+
*
|
|
538
|
+
* @param {Function} successCallback - The callback which will be called when low power mode changes.
|
|
539
|
+
* This callback function is passed a single boolean parameter which is TRUE if low power mode is enabled.
|
|
540
|
+
*/
|
|
541
|
+
Diagnostic.onLowPowerModeChange = function(successCallback) {
|
|
542
|
+
Diagnostic._onLowPowerModeChange = successCallback || function(){};
|
|
543
|
+
};
|
|
544
|
+
|
|
487
545
|
/**
|
|
488
546
|
* Checks if airplane mode is enabled on device.
|
|
489
547
|
*
|
package/www/ios/diagnostic.js
CHANGED
|
@@ -154,6 +154,32 @@ var Diagnostic = (function(){
|
|
|
154
154
|
[]);
|
|
155
155
|
};
|
|
156
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Checks if low power mode is currently enabled on device.
|
|
159
|
+
*
|
|
160
|
+
* @param {Function} successCallback - The callback which will be called when the operation is successful.
|
|
161
|
+
* This callback function is passed a single boolean parameter which is TRUE if low power mode is enabled.
|
|
162
|
+
* @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
|
|
163
|
+
* This callback function is passed a single string parameter containing the error message.
|
|
164
|
+
*/
|
|
165
|
+
Diagnostic.isLowPowerModeEnabled = function(successCallback, errorCallback){
|
|
166
|
+
return cordova.exec(Diagnostic._ensureBoolean(successCallback),
|
|
167
|
+
errorCallback,
|
|
168
|
+
'Diagnostic',
|
|
169
|
+
'isLowPowerModeEnabled',
|
|
170
|
+
[]);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Registers a function to be called when the device low power mode changes.
|
|
175
|
+
*
|
|
176
|
+
* @param {Function} successCallback - The callback which will be called when low power mode changes.
|
|
177
|
+
* This callback function is passed a single boolean parameter which is TRUE if low power mode is enabled.
|
|
178
|
+
*/
|
|
179
|
+
Diagnostic.onLowPowerModeChange = function(successCallback) {
|
|
180
|
+
Diagnostic._onLowPowerModeChange = successCallback || function(){};
|
|
181
|
+
};
|
|
182
|
+
|
|
157
183
|
/**
|
|
158
184
|
* Checks if mobile data is authorized for this app.
|
|
159
185
|
* Returns true if the per-app Mobile Data setting is set to enabled (regardless of whether the device is currently connected to a cellular network)
|
|
@@ -371,8 +397,18 @@ var Diagnostic = (function(){
|
|
|
371
397
|
* This callback function is passed a single string parameter containing the error message.
|
|
372
398
|
* @param {String} mode - (optional) location authorization mode as a constant in `cordova.plugins.diagnostic.locationAuthorizationMode`.
|
|
373
399
|
* If not specified, defaults to `cordova.plugins.diagnostic.locationAuthorizationMode.WHEN_IN_USE`.
|
|
400
|
+
* @param {String} accuracy - (optional) desired location accuracy as a constant in `cordova.plugins.diagnostic.locationAccuracyAuthorization`.
|
|
401
|
+
* If not specified, defaults to `cordova.plugins.diagnostic.locationAccuracyAuthorization.FULL`.
|
|
402
|
+
* On iOS, this sets the CLLocationManager's desiredAccuracy:
|
|
403
|
+
* - `FULL` / `BEST` - kCLLocationAccuracyBest (may engage GPS hardware)
|
|
404
|
+
* - `REDUCED` - kCLLocationAccuracyReduced (approximate location, no GPS)
|
|
405
|
+
* - `BEST_FOR_NAVIGATION` - kCLLocationAccuracyBestForNavigation (highest accuracy with additional sensors)
|
|
406
|
+
* - `NEAREST_TEN_METERS` - kCLLocationAccuracyNearestTenMeters
|
|
407
|
+
* - `HUNDRED_METERS` - kCLLocationAccuracyHundredMeters
|
|
408
|
+
* - `KILOMETER` - kCLLocationAccuracyKilometer
|
|
409
|
+
* - `THREE_KILOMETERS` - kCLLocationAccuracyThreeKilometers
|
|
374
410
|
*/
|
|
375
|
-
Diagnostic.requestLocationAuthorization = function(successCallback, errorCallback, mode) {
|
|
411
|
+
Diagnostic.requestLocationAuthorization = function(successCallback, errorCallback, mode, accuracy) {
|
|
376
412
|
if(cordova.plugins.diagnostic.location){
|
|
377
413
|
cordova.plugins.diagnostic.location.requestLocationAuthorization.apply(this, arguments);
|
|
378
414
|
}else{
|
|
@@ -1218,7 +1254,7 @@ var Diagnostic = (function(){
|
|
|
1218
1254
|
}
|
|
1219
1255
|
};
|
|
1220
1256
|
|
|
1221
|
-
|
|
1257
|
+
Diagnostic._onLowPowerModeChange = function(){};
|
|
1222
1258
|
|
|
1223
1259
|
return Diagnostic;
|
|
1224
1260
|
})();
|
|
@@ -29,7 +29,13 @@ var Diagnostic_Location = (function(){
|
|
|
29
29
|
|
|
30
30
|
Diagnostic.locationAccuracyAuthorization = Diagnostic_Location.locationAccuracyAuthorization = {
|
|
31
31
|
"FULL": "full",
|
|
32
|
-
"REDUCED": "reduced"
|
|
32
|
+
"REDUCED": "reduced",
|
|
33
|
+
"BEST": "best",
|
|
34
|
+
"BEST_FOR_NAVIGATION": "bestForNavigation",
|
|
35
|
+
"NEAREST_TEN_METERS": "nearestTenMeters",
|
|
36
|
+
"HUNDRED_METERS": "hundredMeters",
|
|
37
|
+
"KILOMETER": "kilometer",
|
|
38
|
+
"THREE_KILOMETERS": "threeKilometers"
|
|
33
39
|
};
|
|
34
40
|
|
|
35
41
|
/********************
|
|
@@ -161,13 +167,23 @@ var Diagnostic_Location = (function(){
|
|
|
161
167
|
* This callback function is passed a single string parameter containing the error message.
|
|
162
168
|
* @param {String} mode - (optional) location authorization mode as a constant in `cordova.plugins.diagnostic.locationAuthorizationMode`.
|
|
163
169
|
* If not specified, defaults to `cordova.plugins.diagnostic.locationAuthorizationMode.WHEN_IN_USE`.
|
|
170
|
+
* @param {String} accuracy - (optional) desired location accuracy as a constant in `cordova.plugins.diagnostic.locationAccuracyAuthorization`.
|
|
171
|
+
* If not specified, defaults to `cordova.plugins.diagnostic.locationAccuracyAuthorization.FULL`.
|
|
172
|
+
* On iOS, this sets the CLLocationManager's desiredAccuracy:
|
|
173
|
+
* - `FULL` / `BEST` - kCLLocationAccuracyBest (may engage GPS hardware)
|
|
174
|
+
* - `REDUCED` - kCLLocationAccuracyReduced (approximate location, no GPS)
|
|
175
|
+
* - `BEST_FOR_NAVIGATION` - kCLLocationAccuracyBestForNavigation (highest accuracy with additional sensors)
|
|
176
|
+
* - `NEAREST_TEN_METERS` - kCLLocationAccuracyNearestTenMeters
|
|
177
|
+
* - `HUNDRED_METERS` - kCLLocationAccuracyHundredMeters
|
|
178
|
+
* - `KILOMETER` - kCLLocationAccuracyKilometer
|
|
179
|
+
* - `THREE_KILOMETERS` - kCLLocationAccuracyThreeKilometers
|
|
164
180
|
*/
|
|
165
|
-
Diagnostic_Location.requestLocationAuthorization = function(successCallback, errorCallback, mode) {
|
|
181
|
+
Diagnostic_Location.requestLocationAuthorization = function(successCallback, errorCallback, mode, accuracy) {
|
|
166
182
|
return cordova.exec(successCallback,
|
|
167
183
|
errorCallback,
|
|
168
184
|
'Diagnostic_Location',
|
|
169
185
|
'requestLocationAuthorization',
|
|
170
|
-
[mode && mode === Diagnostic_Location.locationAuthorizationMode.ALWAYS]);
|
|
186
|
+
[mode && mode === Diagnostic_Location.locationAuthorizationMode.ALWAYS, accuracy]);
|
|
171
187
|
};
|
|
172
188
|
|
|
173
189
|
/**
|
package/.specstory/.project.json
DELETED