cordova.plugins.diagnostic 6.0.4

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.
Files changed (75) hide show
  1. package/.github/FUNDING.yml +6 -0
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +123 -0
  3. package/.github/ISSUE_TEMPLATE/documentation-issue.md +36 -0
  4. package/.github/ISSUE_TEMPLATE/feature_request.md +41 -0
  5. package/.github/PULL_REQUEST_TEMPLATE.md +37 -0
  6. package/.github/stale.yml +17 -0
  7. package/CHANGELOG.md +390 -0
  8. package/README.md +3709 -0
  9. package/cordova.plugins.diagnostic.d.ts +1113 -0
  10. package/package.json +54 -0
  11. package/plugin.xml +496 -0
  12. package/scripts/apply-modules.js +165 -0
  13. package/scripts/logger.js +94 -0
  14. package/src/android/Diagnostic.java +856 -0
  15. package/src/android/Diagnostic_Bluetooth.java +297 -0
  16. package/src/android/Diagnostic_Camera.java +134 -0
  17. package/src/android/Diagnostic_External_Storage.java +273 -0
  18. package/src/android/Diagnostic_Location.java +319 -0
  19. package/src/android/Diagnostic_NFC.java +270 -0
  20. package/src/android/Diagnostic_Notifications.java +157 -0
  21. package/src/android/Diagnostic_Wifi.java +155 -0
  22. package/src/ios/Diagnostic.h +56 -0
  23. package/src/ios/Diagnostic.m +282 -0
  24. package/src/ios/Diagnostic_Bluetooth.h +24 -0
  25. package/src/ios/Diagnostic_Bluetooth.m +170 -0
  26. package/src/ios/Diagnostic_Calendar.h +24 -0
  27. package/src/ios/Diagnostic_Calendar.m +94 -0
  28. package/src/ios/Diagnostic_Camera.h +27 -0
  29. package/src/ios/Diagnostic_Camera.m +194 -0
  30. package/src/ios/Diagnostic_Contacts.h +24 -0
  31. package/src/ios/Diagnostic_Contacts.m +93 -0
  32. package/src/ios/Diagnostic_Location.h +31 -0
  33. package/src/ios/Diagnostic_Location.m +284 -0
  34. package/src/ios/Diagnostic_Microphone.h +21 -0
  35. package/src/ios/Diagnostic_Microphone.m +97 -0
  36. package/src/ios/Diagnostic_Motion.h +27 -0
  37. package/src/ios/Diagnostic_Motion.m +143 -0
  38. package/src/ios/Diagnostic_Notifications.h +22 -0
  39. package/src/ios/Diagnostic_Notifications.m +235 -0
  40. package/src/ios/Diagnostic_Reminders.h +24 -0
  41. package/src/ios/Diagnostic_Reminders.m +93 -0
  42. package/src/ios/Diagnostic_Wifi.h +19 -0
  43. package/src/ios/Diagnostic_Wifi.m +108 -0
  44. package/src/windows/diagnosticProxy.bluetooth.js +23 -0
  45. package/src/windows/diagnosticProxy.camera.js +35 -0
  46. package/src/windows/diagnosticProxy.js +137 -0
  47. package/src/windows/diagnosticProxy.location.js +54 -0
  48. package/src/windows/diagnosticProxy.wifi.js +18 -0
  49. package/www/android/diagnostic.bluetooth.js +211 -0
  50. package/www/android/diagnostic.calendar.js +90 -0
  51. package/www/android/diagnostic.camera.js +203 -0
  52. package/www/android/diagnostic.contacts.js +91 -0
  53. package/www/android/diagnostic.external_storage.js +102 -0
  54. package/www/android/diagnostic.js +1309 -0
  55. package/www/android/diagnostic.location.js +282 -0
  56. package/www/android/diagnostic.microphone.js +89 -0
  57. package/www/android/diagnostic.nfc.js +127 -0
  58. package/www/android/diagnostic.notifications.js +74 -0
  59. package/www/android/diagnostic.wifi.js +90 -0
  60. package/www/ios/diagnostic.bluetooth.js +127 -0
  61. package/www/ios/diagnostic.calendar.js +97 -0
  62. package/www/ios/diagnostic.camera.js +212 -0
  63. package/www/ios/diagnostic.contacts.js +98 -0
  64. package/www/ios/diagnostic.js +990 -0
  65. package/www/ios/diagnostic.location.js +236 -0
  66. package/www/ios/diagnostic.microphone.js +99 -0
  67. package/www/ios/diagnostic.motion.js +160 -0
  68. package/www/ios/diagnostic.notifications.js +189 -0
  69. package/www/ios/diagnostic.reminders.js +97 -0
  70. package/www/ios/diagnostic.wifi.js +80 -0
  71. package/www/windows/diagnostic.bluetooth.js +51 -0
  72. package/www/windows/diagnostic.camera.js +41 -0
  73. package/www/windows/diagnostic.js +169 -0
  74. package/www/windows/diagnostic.location.js +35 -0
  75. package/www/windows/diagnostic.wifi.js +51 -0
@@ -0,0 +1,284 @@
1
+ /*
2
+ * Diagnostic_Location.m
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 "Diagnostic_Location.h"
10
+
11
+ @implementation Diagnostic_Location
12
+
13
+ // Internal reference to Diagnostic singleton instance
14
+ static Diagnostic* diagnostic;
15
+
16
+ // Internal constants
17
+ static NSString*const LOG_TAG = @"Diagnostic_Location[native]";
18
+
19
+
20
+ /********************************/
21
+ #pragma mark - Plugin API
22
+ /********************************/
23
+
24
+ - (void) isLocationAvailable: (CDVInvokedUrlCommand*)command
25
+ {
26
+ [self.commandDelegate runInBackground:^{
27
+ @try {
28
+ [diagnostic sendPluginResultBool:[CLLocationManager locationServicesEnabled] && [self isLocationAuthorized] :command];
29
+ }
30
+ @catch (NSException *exception) {
31
+ [diagnostic handlePluginException:exception :command];
32
+ }
33
+ }];
34
+ }
35
+
36
+ - (void) isLocationEnabled: (CDVInvokedUrlCommand*)command
37
+ {
38
+ [self.commandDelegate runInBackground:^{
39
+ @try {
40
+ [diagnostic sendPluginResultBool:[CLLocationManager locationServicesEnabled] :command];
41
+ }
42
+ @catch (NSException *exception) {
43
+ [diagnostic handlePluginException:exception :command];
44
+ }
45
+ }];
46
+ }
47
+
48
+
49
+ - (void) isLocationAuthorized: (CDVInvokedUrlCommand*)command
50
+ {
51
+ [self.commandDelegate runInBackground:^{
52
+ @try {
53
+ [diagnostic sendPluginResultBool:[self isLocationAuthorized] :command];
54
+ }
55
+ @catch (NSException *exception) {
56
+ [diagnostic handlePluginException:exception :command];
57
+ }
58
+ }];
59
+ }
60
+
61
+ - (void) getLocationAuthorizationStatus: (CDVInvokedUrlCommand*)command
62
+ {
63
+ [self.commandDelegate runInBackground:^{
64
+ @try {
65
+ NSString* status = [self getLocationAuthorizationStatusAsString:[self getAuthorizationStatus]];
66
+ [diagnostic logDebug:[NSString stringWithFormat:@"Location authorization status is: %@", status]];
67
+ [diagnostic sendPluginResultString:status:command];
68
+ }
69
+ @catch (NSException *exception) {
70
+ [diagnostic handlePluginException:exception :command];
71
+ }
72
+ }];
73
+ }
74
+
75
+ - (void) requestLocationAuthorization: (CDVInvokedUrlCommand*)command
76
+ {
77
+ [self.commandDelegate runInBackground:^{
78
+ @try {
79
+ if ([CLLocationManager instancesRespondToSelector:@selector(requestWhenInUseAuthorization)])
80
+ {
81
+ BOOL always = [[command argumentAtIndex:0] boolValue];
82
+ if(always){
83
+ NSAssert([[[NSBundle mainBundle] infoDictionary] valueForKey:@"NSLocationAlwaysAndWhenInUseUsageDescription"], @"Your app must have a value for NSLocationAlwaysAndWhenInUseUsageDescription in its Info.plist");
84
+ [self.locationManager requestAlwaysAuthorization];
85
+ [diagnostic logDebug:@"Requesting location authorization: always"];
86
+ }else{
87
+ NSAssert([[[NSBundle mainBundle] infoDictionary] valueForKey:@"NSLocationWhenInUseUsageDescription"], @"Your app must have a value for NSLocationWhenInUseUsageDescription in its Info.plist");
88
+ [self.locationManager requestWhenInUseAuthorization];
89
+ [diagnostic logDebug:@"Requesting location authorization: when in use"];
90
+ }
91
+ }
92
+ }
93
+ @catch (NSException *exception) {
94
+ [diagnostic handlePluginException:exception :command];
95
+ }
96
+ self.locationRequestCallbackId = command.callbackId;
97
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_NO_RESULT];
98
+ [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
99
+ [diagnostic sendPluginResult:pluginResult :command];
100
+ }];
101
+ }
102
+
103
+ - (void) getLocationAccuracyAuthorization: (CDVInvokedUrlCommand*)command{
104
+ [self.commandDelegate runInBackground:^{
105
+ @try {
106
+
107
+ #if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
108
+ if ([CLLocationManager instancesRespondToSelector:@selector(requestTemporaryFullAccuracyAuthorizationWithPurposeKey:completion:)]){
109
+ NSString* locationAccuracyAuthorization = [self getLocationAccuracyAuthorizationAsString:[self.locationManager accuracyAuthorization]];
110
+ [diagnostic logDebug:[NSString stringWithFormat:@"Location accuracy authorization is: %@", locationAccuracyAuthorization]];
111
+ [diagnostic sendPluginResultString:locationAccuracyAuthorization:command];
112
+ }else{
113
+ [diagnostic sendPluginError:@"getLocationAccuracyAuthorization is not available on device running iOS <14":command];
114
+ }
115
+ #else
116
+ [diagnostic sendPluginError:@"getLocationAccuracyAuthorization is not available in builds with iOS SDK <14":command];
117
+ #endif
118
+ }
119
+ @catch (NSException *exception) {
120
+ [diagnostic handlePluginException:exception :command];
121
+ }
122
+ }];
123
+ }
124
+
125
+ - (void) requestTemporaryFullAccuracyAuthorization: (CDVInvokedUrlCommand*)command{
126
+ [self.commandDelegate runInBackground:^{
127
+ @try {
128
+
129
+ #if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
130
+ if ([CLLocationManager instancesRespondToSelector:@selector(requestTemporaryFullAccuracyAuthorizationWithPurposeKey:completion:)]){
131
+ NSAssert([[[NSBundle mainBundle] infoDictionary] valueForKey:@"NSLocationTemporaryUsageDescriptionDictionary"], @"For iOS 14 and above, your app must have a value for NSLocationTemporaryUsageDescriptionDictionary in its Info.plist");
132
+ NSString* purpose = [command argumentAtIndex:0];
133
+ [self.locationManager requestTemporaryFullAccuracyAuthorizationWithPurposeKey:purpose completion:^(NSError* error){
134
+ if(error != nil){
135
+ [diagnostic sendPluginError:[NSString stringWithFormat:@"Error when requesting temporary full location accuracy authorization: %@", error] :command];
136
+ }else{
137
+ NSString* locationAccuracyAuthorization = [self getLocationAccuracyAuthorizationAsString:[self.locationManager accuracyAuthorization]];
138
+ [diagnostic sendPluginResultString:locationAccuracyAuthorization :command];
139
+ }
140
+ }];
141
+ }else{
142
+ [diagnostic sendPluginError:@"requestTemporaryFullAccuracyAuthorization is not available on device running iOS <14":command];
143
+ }
144
+ #else
145
+ [diagnostic sendPluginError:@"requestTemporaryFullAccuracyAuthorization is not available in builds with iOS SDK <14":command];
146
+ #endif
147
+
148
+ }
149
+ @catch (NSException *exception) {
150
+ [diagnostic handlePluginException:exception :command];
151
+ }
152
+ }];
153
+ }
154
+
155
+ /********************************/
156
+ #pragma mark - Internals
157
+ /********************************/
158
+
159
+ - (void)pluginInitialize {
160
+
161
+ [super pluginInitialize];
162
+
163
+ diagnostic = [Diagnostic getInstance];
164
+
165
+ self.locationRequestCallbackId = nil;
166
+ self.currentLocationAuthorizationStatus = nil;
167
+ self.locationManager = [[CLLocationManager alloc] init];
168
+ self.locationManager.delegate = self;
169
+ }
170
+
171
+ - (NSString*) getLocationAuthorizationStatusAsString: (CLAuthorizationStatus)authStatus
172
+ {
173
+ NSString* status;
174
+ if(authStatus == kCLAuthorizationStatusDenied || authStatus == kCLAuthorizationStatusRestricted){
175
+ status = AUTHORIZATION_DENIED;
176
+ }else if(authStatus == kCLAuthorizationStatusNotDetermined){
177
+ status = AUTHORIZATION_NOT_DETERMINED;
178
+ }else if(authStatus == kCLAuthorizationStatusAuthorizedAlways){
179
+ status = AUTHORIZATION_GRANTED;
180
+ }else if(authStatus == kCLAuthorizationStatusAuthorizedWhenInUse){
181
+ status = @"authorized_when_in_use";
182
+ }
183
+ return status;
184
+ }
185
+
186
+ #if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
187
+ - (NSString*) getLocationAccuracyAuthorizationAsString: (CLAccuracyAuthorization)accuracyAuthorization
188
+ {
189
+ NSString* accuracy;
190
+ if(accuracyAuthorization == CLAccuracyAuthorizationFullAccuracy){
191
+ accuracy = @"full";
192
+ }else{
193
+ accuracy = @"reduced";
194
+ }
195
+ return accuracy;
196
+ }
197
+ #endif
198
+
199
+ - (BOOL) isLocationAuthorized
200
+ {
201
+ CLAuthorizationStatus authStatus = [self getAuthorizationStatus];
202
+ NSString* status = [self getLocationAuthorizationStatusAsString:authStatus];
203
+ if([status isEqual: AUTHORIZATION_GRANTED] || [status isEqual: @"authorized_when_in_use"]) {
204
+ return true;
205
+ } else {
206
+ return false;
207
+ }
208
+ }
209
+
210
+ -(CLAuthorizationStatus) getAuthorizationStatus{
211
+ CLAuthorizationStatus authStatus;
212
+ #if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
213
+ if ([CLLocationManager instancesRespondToSelector:@selector(authorizationStatus)]){
214
+ authStatus = [self.locationManager authorizationStatus];
215
+ }else{
216
+ authStatus = [CLLocationManager authorizationStatus];
217
+ }
218
+ #else
219
+ authStatus = [CLLocationManager authorizationStatus];
220
+ #endif
221
+ return authStatus;
222
+ }
223
+
224
+ #if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
225
+ // Note: if built with Xcode >=12 (iOS >=14 SDK) but device is running on iOS <=13, this will not be invoked
226
+ -(void)locationManagerDidChangeAuthorization:(CLLocationManager *)manager{
227
+ // Location authorization status
228
+ [self reportChangeAuthorizationStatus:[self.locationManager authorizationStatus]];
229
+
230
+ // Location accuracy authorization
231
+ NSString* locationAccuracyAuthorization = [self getLocationAccuracyAuthorizationAsString:[self.locationManager accuracyAuthorization]];
232
+ BOOL locationAccuracyAuthorizationChanged = false;
233
+ if(self.currentLocationAccuracyAuthorization != nil && ![locationAccuracyAuthorization isEqual: self.currentLocationAccuracyAuthorization]){
234
+ locationAccuracyAuthorizationChanged = true;
235
+ }
236
+ self.currentLocationAccuracyAuthorization = locationAccuracyAuthorization;
237
+
238
+ if(locationAccuracyAuthorizationChanged){
239
+ [diagnostic logDebug:[NSString stringWithFormat:@"Location accuracy authorization changed to: %@", locationAccuracyAuthorization]];
240
+
241
+ [diagnostic executeGlobalJavascript:[NSString stringWithFormat:@"cordova.plugins.diagnostic.location._onLocationAccuracyAuthorizationChange(\"%@\");", locationAccuracyAuthorization]];
242
+ }
243
+ }
244
+ #endif
245
+
246
+ - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)authStatus {
247
+ #if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
248
+ if ([CLLocationManager instancesRespondToSelector:@selector(authorizationStatus)]){
249
+ // Build SDK & device using iOS >=14 so locationManagerDidChangeAuthorization will be invoked
250
+ }else{
251
+ // Build SDK using iOS >=14 but device running iOS <=13
252
+ [self reportChangeAuthorizationStatus:authStatus];
253
+ }
254
+ #else
255
+ // Device may be running iOS >=14 but build SDK is iOS <=13
256
+ [self reportChangeAuthorizationStatus:authStatus];
257
+ #endif
258
+ }
259
+
260
+
261
+ - (void)reportChangeAuthorizationStatus:(CLAuthorizationStatus)authStatus{
262
+
263
+ NSString* locationAuthorizationStatus = [self getLocationAuthorizationStatusAsString:authStatus];
264
+ BOOL locationAuthorizationStatusChanged = false;
265
+ if(self.currentLocationAuthorizationStatus != nil && ![locationAuthorizationStatus isEqual: self.currentLocationAuthorizationStatus]){
266
+ locationAuthorizationStatusChanged = true;
267
+ }
268
+ self.currentLocationAuthorizationStatus = locationAuthorizationStatus;
269
+
270
+ if(locationAuthorizationStatusChanged){
271
+ [diagnostic logDebug:[NSString stringWithFormat:@"Location authorization status changed to: %@", locationAuthorizationStatus]];
272
+
273
+ if(self.locationRequestCallbackId != nil){
274
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:locationAuthorizationStatus];
275
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:self.locationRequestCallbackId];
276
+ self.locationRequestCallbackId = nil;
277
+ }
278
+
279
+ [diagnostic executeGlobalJavascript:[NSString stringWithFormat:@"cordova.plugins.diagnostic.location._onLocationStateChange(\"%@\");", locationAuthorizationStatus]];
280
+ }
281
+ }
282
+
283
+ @end
284
+
@@ -0,0 +1,21 @@
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 <Cordova/CDV.h>
10
+ #import <Cordova/CDVPlugin.h>
11
+ #import "Diagnostic.h"
12
+
13
+ #import <AVFoundation/AVFoundation.h>
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
@@ -0,0 +1,97 @@
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
@@ -0,0 +1,27 @@
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 <Cordova/CDV.h>
10
+ #import <Cordova/CDVPlugin.h>
11
+ #import "Diagnostic.h"
12
+
13
+ #import <CoreMotion/CoreMotion.h>
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
@@ -0,0 +1,143 @@
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
@@ -0,0 +1,22 @@
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 <Cordova/CDV.h>
10
+ #import <Cordova/CDVPlugin.h>
11
+ #import "Diagnostic.h"
12
+ #import <UserNotifications/UserNotifications.h>
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
+
22
+ @end