cordova.plugins.diagnostic 7.2.3 → 7.2.5
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 +11 -0
- package/README.md +339 -5
- package/cordova.plugins.diagnostic.d.ts +44 -0
- package/package.json +1 -1
- package/plugin.xml +12 -1
- package/src/android/Diagnostic_Bluetooth.java +1 -1
- package/src/android/Diagnostic_Location.java +12 -2
- package/src/ios/Diagnostic.h +2 -0
- package/src/ios/Diagnostic_Location.h +1 -0
- package/src/ios/Diagnostic_Location.m +13 -0
- package/src/ios/Diagnostic_Wifi.h +3 -2
- package/src/ios/Diagnostic_Wifi.m +275 -2
- package/www/android/diagnostic.js +16 -0
- package/www/android/diagnostic.location.js +16 -0
- package/www/ios/diagnostic.js +72 -0
- package/www/ios/diagnostic.location.js +16 -0
- package/www/ios/diagnostic.wifi.js +80 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
**v7.2.5**
|
|
4
|
+
* (ios) feat: add check/request local network authorization to Wifi module
|
|
5
|
+
* Resolves [#524](https://github.com/dpa99c/cordova-diagnostic-plugin/issues/524)
|
|
6
|
+
|
|
7
|
+
**v7.2.4**
|
|
8
|
+
* (android & ios) feat: add `isCompassAvailable()` to detect availability of compass for device heading.
|
|
9
|
+
* (doc) update getCameraRollAuthorizationStatus example to include accessLevel parameter
|
|
10
|
+
* Merged from PR [#532](https://github.com/dpa99c/cordova-diagnostic-plugin/pull/532)
|
|
11
|
+
* (android) fix(Diagnostic_Bluethooth.java): Value null at 0 of type org.json.JSONObject$1 cannot be converted to JSONArray
|
|
12
|
+
* Merged from PR [#529](https://github.com/dpa99c/cordova-diagnostic-plugin/pull/529)
|
|
13
|
+
|
|
3
14
|
**v7.2.3**
|
|
4
15
|
* (android) bugfix: dynamically resolve BuildConfig class (and remove hard-coded example app package name) when determining isDebugBuild()
|
|
5
16
|
|
package/README.md
CHANGED
|
@@ -22,135 +22,353 @@ Cordova diagnostic plugin [
|
|
23
23
|
- [Core module](#core-module)
|
|
24
24
|
- [switchToSettings()](#switchtosettings)
|
|
25
|
+
- [Parameters](#parameters)
|
|
26
|
+
- [Example usage](#example-usage)
|
|
25
27
|
- [switchToWirelessSettings()](#switchtowirelesssettings)
|
|
26
28
|
- [switchToMobileDataSettings()](#switchtomobiledatasettings)
|
|
27
29
|
- [permissionStatus constants](#permissionstatus-constants)
|
|
30
|
+
- [Android](#android)
|
|
31
|
+
- [iOS](#ios)
|
|
32
|
+
- [Example](#example)
|
|
28
33
|
- [getPermissionAuthorizationStatus()](#getpermissionauthorizationstatus)
|
|
34
|
+
- [Parameters](#parameters-1)
|
|
35
|
+
- [Example usage](#example-usage-1)
|
|
29
36
|
- [getPermissionsAuthorizationStatus()](#getpermissionsauthorizationstatus)
|
|
37
|
+
- [Parameters](#parameters-2)
|
|
38
|
+
- [Example usage](#example-usage-2)
|
|
30
39
|
- [requestRuntimePermission()](#requestruntimepermission)
|
|
40
|
+
- [Parameters](#parameters-3)
|
|
41
|
+
- [Example usage](#example-usage-3)
|
|
31
42
|
- [requestRuntimePermissions()](#requestruntimepermissions)
|
|
43
|
+
- [Parameters](#parameters-4)
|
|
44
|
+
- [Example usage](#example-usage-4)
|
|
32
45
|
- [isRequestingPermission()](#isrequestingpermission)
|
|
46
|
+
- [Example usage](#example-usage-5)
|
|
33
47
|
- [registerPermissionRequestCompleteHandler()](#registerpermissionrequestcompletehandler)
|
|
48
|
+
- [Parameters](#parameters-5)
|
|
49
|
+
- [Example usage](#example-usage-6)
|
|
34
50
|
- [isDataRoamingEnabled()](#isdataroamingenabled)
|
|
51
|
+
- [Parameters](#parameters-6)
|
|
52
|
+
- [Example usage](#example-usage-7)
|
|
35
53
|
- [isADBModeEnabled()](#isadbmodeenabled)
|
|
54
|
+
- [Parameters](#parameters-7)
|
|
55
|
+
- [Example usage](#example-usage-8)
|
|
36
56
|
- [isDeviceRooted()](#isdevicerooted)
|
|
57
|
+
- [Parameters](#parameters-8)
|
|
58
|
+
- [Example usage](#example-usage-9)
|
|
37
59
|
- [isBackgroundRefreshAuthorized()](#isbackgroundrefreshauthorized)
|
|
60
|
+
- [Parameters](#parameters-9)
|
|
61
|
+
- [Example usage](#example-usage-10)
|
|
38
62
|
- [getBackgroundRefreshStatus()](#getbackgroundrefreshstatus)
|
|
63
|
+
- [Parameters](#parameters-10)
|
|
64
|
+
- [Example usage](#example-usage-11)
|
|
39
65
|
- [cpuArchitecture constants](#cpuarchitecture-constants)
|
|
66
|
+
- [Android](#android-1)
|
|
67
|
+
- [iOS](#ios-1)
|
|
68
|
+
- [Example usage](#example-usage-12)
|
|
40
69
|
- [getArchitecture()](#getarchitecture)
|
|
70
|
+
- [Parameters](#parameters-11)
|
|
71
|
+
- [Example usage](#example-usage-13)
|
|
41
72
|
- [restart()](#restart)
|
|
73
|
+
- [Parameters](#parameters-12)
|
|
74
|
+
- [Example usage](#example-usage-14)
|
|
42
75
|
- [enableDebug()](#enabledebug)
|
|
76
|
+
- [Parameters](#parameters-13)
|
|
77
|
+
- [Example usage](#example-usage-15)
|
|
43
78
|
- [getCurrentBatteryLevel()](#getcurrentbatterylevel)
|
|
79
|
+
- [Parameters](#parameters-14)
|
|
80
|
+
- [Example usage](#example-usage-16)
|
|
44
81
|
- [isAirplaneModeEnabled()](#isairplanemodeenabled)
|
|
82
|
+
- [Parameters](#parameters-15)
|
|
83
|
+
- [Example usage](#example-usage-17)
|
|
45
84
|
- [isMobileDataEnabled()](#ismobiledataenabled)
|
|
85
|
+
- [Parameters](#parameters-16)
|
|
86
|
+
- [Example usage](#example-usage-18)
|
|
46
87
|
- [isMobileDataAuthorized()](#ismobiledataauthorized)
|
|
88
|
+
- [Parameters](#parameters-17)
|
|
89
|
+
- [Example usage](#example-usage-19)
|
|
47
90
|
- [isAccessibilityModeEnabled()](#isaccessibilitymodeenabled)
|
|
91
|
+
- [Parameters](#parameters-18)
|
|
92
|
+
- [Example usage](#example-usage-20)
|
|
48
93
|
- [isTouchExplorationEnabled()](#istouchexplorationenabled)
|
|
94
|
+
- [Parameters](#parameters-19)
|
|
95
|
+
- [Example usage](#example-usage-21)
|
|
49
96
|
- [getDeviceOSVersion()](#getdeviceosversion)
|
|
97
|
+
- [Parameters](#parameters-20)
|
|
98
|
+
- [Example usage](#example-usage-22)
|
|
50
99
|
- [getBuildOSVersion()](#getbuildosversion)
|
|
100
|
+
- [Parameters](#parameters-21)
|
|
101
|
+
- [Example usage](#example-usage-23)
|
|
51
102
|
- [isDebugBuild()](#isdebugbuild)
|
|
103
|
+
- [Parameters](#parameters-22)
|
|
104
|
+
- [Example usage](#example-usage-24)
|
|
52
105
|
- [Location module](#location-module)
|
|
53
106
|
- [locationMode constants](#locationmode-constants)
|
|
107
|
+
- [Values](#values)
|
|
108
|
+
- [Example](#example-1)
|
|
54
109
|
- [locationAuthorizationMode constants](#locationauthorizationmode-constants)
|
|
110
|
+
- [Values](#values-1)
|
|
111
|
+
- [Example](#example-2)
|
|
55
112
|
- [locationAccuracyAuthorization constants](#locationaccuracyauthorization-constants)
|
|
113
|
+
- [Values](#values-2)
|
|
56
114
|
- [isLocationAvailable()](#islocationavailable)
|
|
115
|
+
- [Parameters](#parameters-23)
|
|
116
|
+
- [Example usage](#example-usage-25)
|
|
57
117
|
- [isLocationEnabled()](#islocationenabled)
|
|
118
|
+
- [Parameters](#parameters-24)
|
|
119
|
+
- [Example usage](#example-usage-26)
|
|
58
120
|
- [isGpsLocationAvailable()](#isgpslocationavailable)
|
|
121
|
+
- [Parameters](#parameters-25)
|
|
122
|
+
- [Example usage](#example-usage-27)
|
|
59
123
|
- [isGpsLocationEnabled()](#isgpslocationenabled)
|
|
124
|
+
- [Parameters](#parameters-26)
|
|
125
|
+
- [Example usage](#example-usage-28)
|
|
126
|
+
- [isCompassAvailable()](#iscompassavailable)
|
|
127
|
+
- [Parameters](#parameters-27)
|
|
128
|
+
- [Example usage](#example-usage-29)
|
|
60
129
|
- [isNetworkLocationAvailable()](#isnetworklocationavailable)
|
|
130
|
+
- [Parameters](#parameters-28)
|
|
131
|
+
- [Example usage](#example-usage-30)
|
|
61
132
|
- [isNetworkLocationEnabled()](#isnetworklocationenabled)
|
|
133
|
+
- [Parameters](#parameters-29)
|
|
134
|
+
- [Example usage](#example-usage-31)
|
|
62
135
|
- [getLocationMode()](#getlocationmode)
|
|
136
|
+
- [Parameters](#parameters-30)
|
|
137
|
+
- [Example usage](#example-usage-32)
|
|
63
138
|
- [isLocationAuthorized()](#islocationauthorized)
|
|
139
|
+
- [Parameters](#parameters-31)
|
|
140
|
+
- [Example usage](#example-usage-33)
|
|
64
141
|
- [getLocationAuthorizationStatus()](#getlocationauthorizationstatus)
|
|
142
|
+
- [Parameters](#parameters-32)
|
|
143
|
+
- [Example iOS usage](#example-ios-usage)
|
|
144
|
+
- [Example Android usage](#example-android-usage)
|
|
65
145
|
- [getLocationAuthorizationStatuses()](#getlocationauthorizationstatuses)
|
|
146
|
+
- [Parameters](#parameters-33)
|
|
66
147
|
- [requestLocationAuthorization()](#requestlocationauthorization)
|
|
148
|
+
- [Parameters](#parameters-34)
|
|
149
|
+
- [Example usage](#example-usage-34)
|
|
67
150
|
- [registerLocationStateChangeHandler()](#registerlocationstatechangehandler)
|
|
151
|
+
- [Parameters](#parameters-35)
|
|
152
|
+
- [Example usage](#example-usage-35)
|
|
68
153
|
- [getLocationAccuracyAuthorization()](#getlocationaccuracyauthorization)
|
|
154
|
+
- [Parameters](#parameters-36)
|
|
155
|
+
- [Example usage](#example-usage-36)
|
|
69
156
|
- [requestTemporaryFullAccuracyAuthorization()](#requesttemporaryfullaccuracyauthorization)
|
|
157
|
+
- [Parameters](#parameters-37)
|
|
158
|
+
- [Example usage](#example-usage-37)
|
|
70
159
|
- [registerLocationAccuracyAuthorizationChangeHandler()](#registerlocationaccuracyauthorizationchangehandler)
|
|
160
|
+
- [Parameters](#parameters-38)
|
|
161
|
+
- [Example usage](#example-usage-38)
|
|
71
162
|
- [switchToLocationSettings()](#switchtolocationsettings)
|
|
72
163
|
- [Bluetooth module](#bluetooth-module)
|
|
73
164
|
- [bluetoothState constants](#bluetoothstate-constants)
|
|
165
|
+
- [Android](#android-2)
|
|
166
|
+
- [iOS](#ios-2)
|
|
167
|
+
- [Example](#example-3)
|
|
74
168
|
- [isBluetoothAvailable()](#isbluetoothavailable)
|
|
169
|
+
- [Parameters](#parameters-39)
|
|
170
|
+
- [Example usage](#example-usage-39)
|
|
75
171
|
- [isBluetoothEnabled()](#isbluetoothenabled)
|
|
172
|
+
- [Parameters](#parameters-40)
|
|
173
|
+
- [Example usage](#example-usage-40)
|
|
76
174
|
- [hasBluetoothSupport()](#hasbluetoothsupport)
|
|
175
|
+
- [Parameters](#parameters-41)
|
|
176
|
+
- [Example usage](#example-usage-41)
|
|
77
177
|
- [hasBluetoothLESupport()](#hasbluetoothlesupport)
|
|
178
|
+
- [Parameters](#parameters-42)
|
|
179
|
+
- [Example usage](#example-usage-42)
|
|
78
180
|
- [hasBluetoothLEPeripheralSupport()](#hasbluetoothleperipheralsupport)
|
|
181
|
+
- [Parameters](#parameters-43)
|
|
182
|
+
- [Example usage](#example-usage-43)
|
|
79
183
|
- [getBluetoothState()](#getbluetoothstate)
|
|
184
|
+
- [Parameters](#parameters-44)
|
|
185
|
+
- [Example usage](#example-usage-44)
|
|
80
186
|
- [setBluetoothState()](#setbluetoothstate)
|
|
187
|
+
- [Parameters](#parameters-45)
|
|
188
|
+
- [Example usage](#example-usage-45)
|
|
81
189
|
- [getBluetoothAuthorizationStatus()](#getbluetoothauthorizationstatus)
|
|
190
|
+
- [Parameters](#parameters-46)
|
|
191
|
+
- [Example usage](#example-usage-46)
|
|
82
192
|
- [getBluetoothAuthorizationStatuses()](#getbluetoothauthorizationstatuses)
|
|
193
|
+
- [Parameters](#parameters-47)
|
|
194
|
+
- [Example usage](#example-usage-47)
|
|
83
195
|
- [requestBluetoothAuthorization()](#requestbluetoothauthorization)
|
|
196
|
+
- [Parameters](#parameters-48)
|
|
197
|
+
- [Example usage](#example-usage-48)
|
|
84
198
|
- [registerBluetoothStateChangeHandler()](#registerbluetoothstatechangehandler)
|
|
199
|
+
- [Parameters](#parameters-49)
|
|
200
|
+
- [Example usage](#example-usage-49)
|
|
85
201
|
- [switchToBluetoothSettings()](#switchtobluetoothsettings)
|
|
86
202
|
- [WiFi module](#wifi-module)
|
|
87
203
|
- [isWifiAvailable()](#iswifiavailable)
|
|
204
|
+
- [Parameters](#parameters-50)
|
|
205
|
+
- [Example usage](#example-usage-50)
|
|
88
206
|
- [isWifiEnabled()](#iswifienabled)
|
|
207
|
+
- [Parameters](#parameters-51)
|
|
208
|
+
- [Example usage](#example-usage-51)
|
|
209
|
+
- [isLocalNetworkAuthorized()](#islocalnetworkauthorized)
|
|
210
|
+
- [Parameters](#parameters-52)
|
|
211
|
+
- [Example usage](#example-usage-52)
|
|
212
|
+
- [getLocalNetworkAuthorizationStatus()](#getlocalnetworkauthorizationstatus)
|
|
213
|
+
- [Parameters](#parameters-53)
|
|
214
|
+
- [Example usage](#example-usage-53)
|
|
215
|
+
- [requestLocalNetworkAuthorization()](#requestlocalnetworkauthorization)
|
|
216
|
+
- [Parameters](#parameters-54)
|
|
217
|
+
- [Example usage](#example-usage-54)
|
|
89
218
|
- [setWifiState()](#setwifistate)
|
|
219
|
+
- [Parameters](#parameters-55)
|
|
220
|
+
- [Example usage](#example-usage-55)
|
|
90
221
|
- [switchToWifiSettings()](#switchtowifisettings)
|
|
91
222
|
- [Camera module](#camera-module)
|
|
92
223
|
- [isCameraPresent()](#iscamerapresent)
|
|
224
|
+
- [Parameters](#parameters-56)
|
|
225
|
+
- [Example usage](#example-usage-56)
|
|
93
226
|
- [isCameraAvailable()](#iscameraavailable)
|
|
227
|
+
- [Parameters](#parameters-57)
|
|
228
|
+
- [Example usage](#example-usage-57)
|
|
94
229
|
- [isCameraAuthorized()](#iscameraauthorized)
|
|
230
|
+
- [Parameters](#parameters-58)
|
|
231
|
+
- [Example usage](#example-usage-58)
|
|
95
232
|
- [getCameraAuthorizationStatus()](#getcameraauthorizationstatus)
|
|
233
|
+
- [Parameters](#parameters-59)
|
|
234
|
+
- [Example usage](#example-usage-59)
|
|
96
235
|
- [getCameraAuthorizationStatuses()](#getcameraauthorizationstatuses)
|
|
236
|
+
- [Parameters](#parameters-60)
|
|
237
|
+
- [Example usage](#example-usage-60)
|
|
97
238
|
- [requestCameraAuthorization()](#requestcameraauthorization)
|
|
239
|
+
- [Parameters](#parameters-61)
|
|
240
|
+
- [Example usage](#example-usage-61)
|
|
98
241
|
- [isCameraRollAuthorized()](#iscamerarollauthorized)
|
|
242
|
+
- [Parameters](#parameters-62)
|
|
243
|
+
- [Example usage](#example-usage-62)
|
|
99
244
|
- [getCameraRollAuthorizationStatus()](#getcamerarollauthorizationstatus)
|
|
245
|
+
- [Parameters](#parameters-63)
|
|
246
|
+
- [Example usage](#example-usage-63)
|
|
100
247
|
- [requestCameraRollAuthorization()](#requestcamerarollauthorization)
|
|
248
|
+
- [Parameters](#parameters-64)
|
|
249
|
+
- [Example usage](#example-usage-64)
|
|
101
250
|
- [presentLimitedLibraryPicker()](#presentlimitedlibrarypicker)
|
|
251
|
+
- [Parameters](#parameters-65)
|
|
252
|
+
- [Example usage](#example-usage-65)
|
|
102
253
|
- [Notifications module](#notifications-module)
|
|
103
254
|
- [remoteNotificationType constants](#remotenotificationtype-constants)
|
|
255
|
+
- [Example](#example-4)
|
|
104
256
|
- [isRemoteNotificationsEnabled()](#isremotenotificationsenabled)
|
|
257
|
+
- [Parameters](#parameters-66)
|
|
258
|
+
- [Example usage](#example-usage-66)
|
|
105
259
|
- [isRegisteredForRemoteNotifications()](#isregisteredforremotenotifications)
|
|
260
|
+
- [Parameters](#parameters-67)
|
|
261
|
+
- [Example usage](#example-usage-67)
|
|
106
262
|
- [getRemoteNotificationTypes()](#getremotenotificationtypes)
|
|
263
|
+
- [Parameters](#parameters-68)
|
|
264
|
+
- [Example usage](#example-usage-68)
|
|
107
265
|
- [getRemoteNotificationsAuthorizationStatus()](#getremotenotificationsauthorizationstatus)
|
|
266
|
+
- [Parameters](#parameters-69)
|
|
267
|
+
- [Example usage](#example-usage-69)
|
|
108
268
|
- [requestRemoteNotificationsAuthorization()](#requestremotenotificationsauthorization)
|
|
269
|
+
- [Parameters](#parameters-70)
|
|
270
|
+
- [Example usage](#example-usage-70)
|
|
109
271
|
- [switchToNotificationSettings()](#switchtonotificationsettings)
|
|
110
272
|
- [Microphone module](#microphone-module)
|
|
111
273
|
- [isMicrophoneAuthorized()](#ismicrophoneauthorized)
|
|
274
|
+
- [Parameters](#parameters-71)
|
|
275
|
+
- [Example usage](#example-usage-71)
|
|
112
276
|
- [getMicrophoneAuthorizationStatus()](#getmicrophoneauthorizationstatus)
|
|
277
|
+
- [Parameters](#parameters-72)
|
|
278
|
+
- [Example usage](#example-usage-72)
|
|
113
279
|
- [requestMicrophoneAuthorization()](#requestmicrophoneauthorization)
|
|
280
|
+
- [Parameters](#parameters-73)
|
|
281
|
+
- [Example usage](#example-usage-73)
|
|
114
282
|
- [Contacts module](#contacts-module)
|
|
115
283
|
- [isContactsAuthorized()](#iscontactsauthorized)
|
|
284
|
+
- [Parameters](#parameters-74)
|
|
285
|
+
- [Example usage](#example-usage-74)
|
|
116
286
|
- [getContactsAuthorizationStatus()](#getcontactsauthorizationstatus)
|
|
287
|
+
- [Parameters](#parameters-75)
|
|
288
|
+
- [Example usage](#example-usage-75)
|
|
117
289
|
- [requestContactsAuthorization()](#requestcontactsauthorization)
|
|
290
|
+
- [Parameters](#parameters-76)
|
|
291
|
+
- [Example usage](#example-usage-76)
|
|
118
292
|
- [Calendar module](#calendar-module)
|
|
119
293
|
- [isCalendarAuthorized()](#iscalendarauthorized)
|
|
294
|
+
- [Parameters](#parameters-77)
|
|
295
|
+
- [Example usage](#example-usage-77)
|
|
120
296
|
- [getCalendarAuthorizationStatus()](#getcalendarauthorizationstatus)
|
|
297
|
+
- [Parameters](#parameters-78)
|
|
298
|
+
- [Example usage](#example-usage-78)
|
|
121
299
|
- [requestCalendarAuthorization()](#requestcalendarauthorization)
|
|
300
|
+
- [Parameters](#parameters-79)
|
|
301
|
+
- [Example usage](#example-usage-79)
|
|
122
302
|
- [Reminders module](#reminders-module)
|
|
123
303
|
- [isRemindersAuthorized()](#isremindersauthorized)
|
|
304
|
+
- [Parameters](#parameters-80)
|
|
305
|
+
- [Example usage](#example-usage-80)
|
|
124
306
|
- [getRemindersAuthorizationStatus()](#getremindersauthorizationstatus)
|
|
307
|
+
- [Parameters](#parameters-81)
|
|
308
|
+
- [Example usage](#example-usage-81)
|
|
125
309
|
- [requestRemindersAuthorization()](#requestremindersauthorization)
|
|
310
|
+
- [Parameters](#parameters-82)
|
|
311
|
+
- [Example usage](#example-usage-82)
|
|
126
312
|
- [Motion module](#motion-module)
|
|
127
313
|
- [motionStatus constants](#motionstatus-constants)
|
|
314
|
+
- [Example](#example-5)
|
|
128
315
|
- [isMotionAvailable()](#ismotionavailable)
|
|
316
|
+
- [Parameters](#parameters-83)
|
|
317
|
+
- [Example usage](#example-usage-83)
|
|
129
318
|
- [isMotionRequestOutcomeAvailable()](#ismotionrequestoutcomeavailable)
|
|
319
|
+
- [Parameters](#parameters-84)
|
|
320
|
+
- [Example usage](#example-usage-84)
|
|
130
321
|
- [requestMotionAuthorization()](#requestmotionauthorization)
|
|
322
|
+
- [Parameters](#parameters-85)
|
|
323
|
+
- [Example usage](#example-usage-85)
|
|
131
324
|
- [getMotionAuthorizationStatus()](#getmotionauthorizationstatus)
|
|
325
|
+
- [Parameters](#parameters-86)
|
|
326
|
+
- [Example usage](#example-usage-86)
|
|
132
327
|
- [NFC module](#nfc-module)
|
|
133
328
|
- [NFCState constants](#nfcstate-constants)
|
|
329
|
+
- [Values](#values-3)
|
|
330
|
+
- [Example](#example-6)
|
|
134
331
|
- [isNFCPresent()](#isnfcpresent)
|
|
332
|
+
- [Parameters](#parameters-87)
|
|
333
|
+
- [Example usage](#example-usage-87)
|
|
135
334
|
- [isNFCEnabled()](#isnfcenabled)
|
|
335
|
+
- [Parameters](#parameters-88)
|
|
336
|
+
- [Example usage](#example-usage-88)
|
|
136
337
|
- [isNFCAvailable()](#isnfcavailable)
|
|
338
|
+
- [Parameters](#parameters-89)
|
|
339
|
+
- [Example usage](#example-usage-89)
|
|
137
340
|
- [registerNFCStateChangeHandler()](#registernfcstatechangehandler)
|
|
341
|
+
- [Parameters](#parameters-90)
|
|
342
|
+
- [Example usage](#example-usage-90)
|
|
138
343
|
- [switchToNFCSettings()](#switchtonfcsettings)
|
|
139
344
|
- [External storage module](#external-storage-module)
|
|
140
345
|
- [isExternalStorageAuthorized()](#isexternalstorageauthorized)
|
|
346
|
+
- [Parameters](#parameters-91)
|
|
347
|
+
- [Example usage](#example-usage-91)
|
|
141
348
|
- [getExternalStorageAuthorizationStatus()](#getexternalstorageauthorizationstatus)
|
|
349
|
+
- [Parameters](#parameters-92)
|
|
350
|
+
- [Example usage](#example-usage-92)
|
|
142
351
|
- [requestExternalStorageAuthorization()](#requestexternalstorageauthorization)
|
|
352
|
+
- [Parameters](#parameters-93)
|
|
353
|
+
- [Example usage](#example-usage-93)
|
|
143
354
|
- [getExternalSdCardDetails()](#getexternalsdcarddetails)
|
|
355
|
+
- [Parameters](#parameters-94)
|
|
356
|
+
- [Example usage](#example-usage-94)
|
|
144
357
|
- [Platform Notes](#platform-notes)
|
|
145
|
-
- [Android](#android)
|
|
358
|
+
- [Android](#android-3)
|
|
146
359
|
- [Android permissions](#android-permissions)
|
|
360
|
+
- [Android runtime permissions](#android-runtime-permissions)
|
|
361
|
+
- ["Dangerous" runtime permissions](#dangerous-runtime-permissions)
|
|
362
|
+
- [Android 11+ runtime permissions](#android-11-runtime-permissions)
|
|
363
|
+
- [Runtime permissions example project](#runtime-permissions-example-project)
|
|
364
|
+
- [Android Camera permissions](#android-camera-permissions)
|
|
147
365
|
- [Android Auto Backup](#android-auto-backup)
|
|
148
|
-
- [iOS](#ios)
|
|
366
|
+
- [iOS](#ios-3)
|
|
149
367
|
- [iOS usage description messages](#ios-usage-description-messages)
|
|
150
368
|
- [Example project](#example-project)
|
|
151
369
|
- [Screenshots](#screenshots)
|
|
152
|
-
- [Android](#android-
|
|
153
|
-
- [iOS](#ios-
|
|
370
|
+
- [Android](#android-4)
|
|
371
|
+
- [iOS](#ios-4)
|
|
154
372
|
- [Release notes](#release-notes)
|
|
155
373
|
- [Credits](#credits)
|
|
156
374
|
- [License](#license)
|
|
@@ -1317,6 +1535,30 @@ The function is passed a single string parameter containing the error message.
|
|
|
1317
1535
|
console.error("The following error occurred: "+error);
|
|
1318
1536
|
});
|
|
1319
1537
|
|
|
1538
|
+
### isCompassAvailable()
|
|
1539
|
+
|
|
1540
|
+
Platforms: Android & iOS
|
|
1541
|
+
|
|
1542
|
+
Checks if app is able to access device heading.
|
|
1543
|
+
|
|
1544
|
+
cordova.plugins.diagnostic.isCompassAvailable(successCallback, errorCallback);
|
|
1545
|
+
|
|
1546
|
+
#### Parameters
|
|
1547
|
+
|
|
1548
|
+
- {Function} successCallback - The callback which will be called when operation is successful.
|
|
1549
|
+
The function is passed a single boolean parameter which is TRUE if compass is available for use.
|
|
1550
|
+
- {Function} errorCallback - The callback which will be called when operation encounters an error.
|
|
1551
|
+
The function is passed a single string parameter containing the error message.
|
|
1552
|
+
|
|
1553
|
+
|
|
1554
|
+
#### Example usage
|
|
1555
|
+
|
|
1556
|
+
cordova.plugins.diagnostic.isCompassAvailable(function(available){
|
|
1557
|
+
console.log("Compass is " + (available ? "available" : "not available"));
|
|
1558
|
+
}, function(error){
|
|
1559
|
+
console.error("The following error occurred: "+error);
|
|
1560
|
+
});
|
|
1561
|
+
|
|
1320
1562
|
### isNetworkLocationAvailable()
|
|
1321
1563
|
|
|
1322
1564
|
Platforms: Android
|
|
@@ -2209,6 +2451,98 @@ The function is passed a single string parameter containing the error message.
|
|
|
2209
2451
|
console.error("The following error occurred: "+error);
|
|
2210
2452
|
});
|
|
2211
2453
|
|
|
2454
|
+
### isLocalNetworkAuthorized()
|
|
2455
|
+
|
|
2456
|
+
Platforms: iOS
|
|
2457
|
+
|
|
2458
|
+
Checks if the app is authorised to access devices on the local network (iOS 14+).
|
|
2459
|
+
On iOS versions prior to 14 this will always return TRUE as no local network authorization is required.
|
|
2460
|
+
|
|
2461
|
+
cordova.plugins.diagnostic.isLocalNetworkAuthorized(successCallback, errorCallback);
|
|
2462
|
+
|
|
2463
|
+
#### Parameters
|
|
2464
|
+
|
|
2465
|
+
- {Function} successCallback - The callback which will be called when operation is successful.
|
|
2466
|
+
The function is passed a single boolean parameter which is TRUE if the app is authorised to use the Local Network.
|
|
2467
|
+
- {Function} errorCallback - The callback which will be called when operation encounters an error.
|
|
2468
|
+
The function is passed a single string parameter containing the error message.
|
|
2469
|
+
|
|
2470
|
+
|
|
2471
|
+
#### Example usage
|
|
2472
|
+
|
|
2473
|
+
cordova.plugins.diagnostic.isLocalNetworkAuthorized(function(authorized){
|
|
2474
|
+
console.log("Local Network is " + (authorized ? "authorized" : "unauthorised"));
|
|
2475
|
+
}, function(error){
|
|
2476
|
+
console.error("The following error occurred: "+error);
|
|
2477
|
+
});
|
|
2478
|
+
|
|
2479
|
+
### getLocalNetworkAuthorizationStatus()
|
|
2480
|
+
|
|
2481
|
+
Platforms: iOS
|
|
2482
|
+
|
|
2483
|
+
Returns the app's Local Network authorization status.
|
|
2484
|
+
On iOS 14+ this returns one of the values in `cordova.plugins.diagnostic.permissionStatus`: `NOT_REQUESTED`, `GRANTED`, `DENIED_ALWAYS`.
|
|
2485
|
+
On iOS versions prior to 14 this will always return `GRANTED` as no authorization is required.
|
|
2486
|
+
|
|
2487
|
+
cordova.plugins.diagnostic.getLocalNetworkAuthorizationStatus(successCallback, errorCallback);
|
|
2488
|
+
|
|
2489
|
+
#### Parameters
|
|
2490
|
+
|
|
2491
|
+
- {Function} successCallback - The callback which will be called when operation is successful.
|
|
2492
|
+
The function is passed a single string parameter which is one of the values in `cordova.plugins.diagnostic.permissionStatus`:
|
|
2493
|
+
`NOT_REQUESTED`, `GRANTED`, `DENIED_ALWAYS`.
|
|
2494
|
+
- {Function} errorCallback - The callback which will be called when operation encounters an error.
|
|
2495
|
+
The function is passed a single string parameter containing the error message.
|
|
2496
|
+
|
|
2497
|
+
|
|
2498
|
+
#### Example usage
|
|
2499
|
+
|
|
2500
|
+
cordova.plugins.diagnostic.getLocalNetworkAuthorizationStatus(function(status){
|
|
2501
|
+
switch(status){
|
|
2502
|
+
case cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED:
|
|
2503
|
+
console.log("Local Network permission not requested");
|
|
2504
|
+
break;
|
|
2505
|
+
case cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS:
|
|
2506
|
+
console.log("Local Network permission denied");
|
|
2507
|
+
break;
|
|
2508
|
+
case cordova.plugins.diagnostic.permissionStatus.GRANTED:
|
|
2509
|
+
console.log("Local Network permission granted");
|
|
2510
|
+
break;
|
|
2511
|
+
}
|
|
2512
|
+
}, function(error){
|
|
2513
|
+
console.error("The following error occurred: "+error);
|
|
2514
|
+
});
|
|
2515
|
+
|
|
2516
|
+
### requestLocalNetworkAuthorization()
|
|
2517
|
+
|
|
2518
|
+
Platforms: iOS
|
|
2519
|
+
|
|
2520
|
+
Requests the user to authorise the app to access devices on the local network (iOS 14+).
|
|
2521
|
+
On iOS versions prior to 14 this does nothing and will return success as no authorization is required.
|
|
2522
|
+
|
|
2523
|
+
cordova.plugins.diagnostic.requestLocalNetworkAuthorization(successCallback, errorCallback);
|
|
2524
|
+
|
|
2525
|
+
#### Parameters
|
|
2526
|
+
|
|
2527
|
+
- {Function} successCallback - The callback which will be called when operation is successful.
|
|
2528
|
+
The function is passed a single string parameter which is one of the values in `cordova.plugins.diagnostic.permissionStatus`:
|
|
2529
|
+
`NOT_REQUESTED`, `GRANTED`, `DENIED_ALWAYS`.
|
|
2530
|
+
- {Function} errorCallback - The callback which will be called when operation encounters an error.
|
|
2531
|
+
The function is passed a single string parameter containing the error message.
|
|
2532
|
+
|
|
2533
|
+
|
|
2534
|
+
#### Example usage
|
|
2535
|
+
|
|
2536
|
+
cordova.plugins.diagnostic.requestLocalNetworkAuthorization(function(status){
|
|
2537
|
+
if(status === cordova.plugins.diagnostic.permissionStatus.GRANTED){
|
|
2538
|
+
console.log("Local Network access granted");
|
|
2539
|
+
}else{
|
|
2540
|
+
console.log("Local Network access not granted: " + status);
|
|
2541
|
+
}
|
|
2542
|
+
}, function(error){
|
|
2543
|
+
console.error("The following error occurred: "+error);
|
|
2544
|
+
});
|
|
2545
|
+
|
|
2212
2546
|
### setWifiState()
|
|
2213
2547
|
|
|
2214
2548
|
Platforms: Android
|
|
@@ -2498,7 +2832,7 @@ Platforms: iOS
|
|
|
2498
2832
|
|
|
2499
2833
|
Returns the authorization status for the application to use the Camera Roll in Photos app.
|
|
2500
2834
|
|
|
2501
|
-
cordova.plugins.diagnostic.getCameraRollAuthorizationStatus(successCallback, errorCallback);
|
|
2835
|
+
cordova.plugins.diagnostic.getCameraRollAuthorizationStatus(successCallback, errorCallback, accessLevel);
|
|
2502
2836
|
|
|
2503
2837
|
#### Parameters
|
|
2504
2838
|
|
|
@@ -200,6 +200,16 @@ interface Diagnostic {
|
|
|
200
200
|
errorCallback: (error: string) => void
|
|
201
201
|
) => void;
|
|
202
202
|
|
|
203
|
+
/**
|
|
204
|
+
* Checks if app is able to access device heading.
|
|
205
|
+
* @param successCallback
|
|
206
|
+
* @param errorCallback
|
|
207
|
+
*/
|
|
208
|
+
isCompassAvailable: (
|
|
209
|
+
successCallback: (available: boolean) => void,
|
|
210
|
+
errorCallback: (error: string) => void
|
|
211
|
+
) => void;
|
|
212
|
+
|
|
203
213
|
/**
|
|
204
214
|
* Checks if Wifi is available.
|
|
205
215
|
* On iOS this returns true if the device is connected to a network by WiFi.
|
|
@@ -236,6 +246,7 @@ interface Diagnostic {
|
|
|
236
246
|
errorCallback: (error: string) => void
|
|
237
247
|
) => void;
|
|
238
248
|
|
|
249
|
+
|
|
239
250
|
/**
|
|
240
251
|
* ANDROID ONLY
|
|
241
252
|
* Displays the device location settings to allow user to enable location services/change location mode.
|
|
@@ -1252,6 +1263,39 @@ interface Diagnostic {
|
|
|
1252
1263
|
successCallback: (status: string) => void,
|
|
1253
1264
|
errorCallback: (error: string) => void
|
|
1254
1265
|
) => void;
|
|
1266
|
+
|
|
1267
|
+
/**
|
|
1268
|
+
* iOS ONLY
|
|
1269
|
+
* Checks if the application is authorized to use local network.
|
|
1270
|
+
* @param successCallback
|
|
1271
|
+
* @param errorCallback
|
|
1272
|
+
*/
|
|
1273
|
+
isLocalNetworkAuthorized?: (
|
|
1274
|
+
successCallback: (authorized: boolean) => void,
|
|
1275
|
+
errorCallback: (error: string) => void
|
|
1276
|
+
) => void;
|
|
1277
|
+
|
|
1278
|
+
/**
|
|
1279
|
+
* iOS ONLY
|
|
1280
|
+
* Returns the local network authorization status for the application.
|
|
1281
|
+
* @param successCallback
|
|
1282
|
+
* @param errorCallback
|
|
1283
|
+
*/
|
|
1284
|
+
getLocalNetworkAuthorizationStatus?: (
|
|
1285
|
+
successCallback: (status: string) => void,
|
|
1286
|
+
errorCallback: (error: string) => void
|
|
1287
|
+
) => void;
|
|
1288
|
+
|
|
1289
|
+
/**
|
|
1290
|
+
* iOS ONLY
|
|
1291
|
+
* Requests local network authorization for the application.
|
|
1292
|
+
* @param successCallback
|
|
1293
|
+
* @param errorCallback
|
|
1294
|
+
*/
|
|
1295
|
+
requestLocalNetworkAuthorization?: (
|
|
1296
|
+
successCallback: (status: string) => void,
|
|
1297
|
+
errorCallback: (error: string) => void
|
|
1298
|
+
) => void;
|
|
1255
1299
|
}
|
|
1256
1300
|
|
|
1257
1301
|
interface CordovaPlugins {
|
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.2.
|
|
5
|
+
version="7.2.5">
|
|
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>
|
|
@@ -104,6 +104,17 @@
|
|
|
104
104
|
|
|
105
105
|
<header-file src="src/ios/Diagnostic_Wifi.h" />
|
|
106
106
|
<source-file src="src/ios/Diagnostic_Wifi.m" />
|
|
107
|
+
|
|
108
|
+
<config-file parent="NSLocalNetworkUsageDescription" platform="ios" target="*-Info.plist">
|
|
109
|
+
<string>This app requires access to your local network in order to discover and connect to devices on the same network.</string>
|
|
110
|
+
</config-file>
|
|
111
|
+
|
|
112
|
+
<config-file parent="NSBonjourServices" platform="ios" target="*-Info.plist">
|
|
113
|
+
<array>
|
|
114
|
+
<string>_lnp._tcp.</string>
|
|
115
|
+
<string>_bonjour._tcp.</string>
|
|
116
|
+
</array>
|
|
117
|
+
</config-file>
|
|
107
118
|
<!--END_MODULE WIFI-->
|
|
108
119
|
|
|
109
120
|
<!--BEGIN_MODULE CAMERA-->
|
|
@@ -327,7 +327,7 @@ public class Diagnostic_Bluetooth extends CordovaPlugin {
|
|
|
327
327
|
|
|
328
328
|
public void requestBluetoothAuthorization(JSONArray args, CallbackContext callbackContext) throws Exception {
|
|
329
329
|
JSONArray permissionsToRequest = new JSONArray();
|
|
330
|
-
if(args.length() > 0){
|
|
330
|
+
if(args.length() > 0 && args.get(0) instanceof JSONArray){
|
|
331
331
|
JSONArray specifiedPermissions = args.getJSONArray(0);
|
|
332
332
|
if(specifiedPermissions.length() > 0){
|
|
333
333
|
for (int i = 0, size = specifiedPermissions.length(); i < size; i++){
|
|
@@ -31,6 +31,8 @@ import org.json.JSONException;
|
|
|
31
31
|
|
|
32
32
|
import android.content.BroadcastReceiver;
|
|
33
33
|
import android.content.IntentFilter;
|
|
34
|
+
import android.hardware.Sensor;
|
|
35
|
+
import android.hardware.SensorManager;
|
|
34
36
|
import android.location.LocationManager;
|
|
35
37
|
import android.os.Build;
|
|
36
38
|
import android.util.Log;
|
|
@@ -164,7 +166,9 @@ public class Diagnostic_Location extends CordovaPlugin{
|
|
|
164
166
|
callbackContext.success(getLocationModeName());
|
|
165
167
|
} else if(action.equals("requestLocationAuthorization")) {
|
|
166
168
|
requestLocationAuthorization(args, callbackContext);
|
|
167
|
-
}else {
|
|
169
|
+
} else if(action.equals("isCompassAvailable")) {
|
|
170
|
+
callbackContext.success(isCompassAvailable() ? 1 : 0);
|
|
171
|
+
} else {
|
|
168
172
|
diagnostic.handleError("Invalid action");
|
|
169
173
|
return false;
|
|
170
174
|
}
|
|
@@ -264,7 +268,13 @@ public class Diagnostic_Location extends CordovaPlugin{
|
|
|
264
268
|
callbackContext.sendPluginResult(result);
|
|
265
269
|
}
|
|
266
270
|
|
|
267
|
-
|
|
271
|
+
public boolean isCompassAvailable() {
|
|
272
|
+
SensorManager sensorManager = (SensorManager) this.cordova.getContext().getSystemService(Context.SENSOR_SERVICE);
|
|
273
|
+
boolean result = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null;
|
|
274
|
+
// true if device has a magnetic field sensor (magnetometer)
|
|
275
|
+
diagnostic.logDebug("Compass available: " + result);
|
|
276
|
+
return result;
|
|
277
|
+
}
|
|
268
278
|
|
|
269
279
|
/************
|
|
270
280
|
* Internals
|
package/src/ios/Diagnostic.h
CHANGED
|
@@ -47,6 +47,8 @@ extern NSString*const AUTHORIZATION_LIMITED;
|
|
|
47
47
|
- (void) sendPluginResultSuccess:(CDVInvokedUrlCommand*)command;
|
|
48
48
|
- (void) sendPluginNoResultAndKeepCallback:(CDVInvokedUrlCommand*)command;
|
|
49
49
|
- (void) sendPluginResultBool: (BOOL)result :(CDVInvokedUrlCommand*)command;
|
|
50
|
+
- (void) sendPluginResultInt: (int)result :(CDVInvokedUrlCommand*)command;
|
|
51
|
+
- (void) sendPluginResultObject: (NSDictionary*)result :(CDVInvokedUrlCommand*)command;
|
|
50
52
|
- (void) sendPluginResultString: (NSString*)result :(CDVInvokedUrlCommand*)command;
|
|
51
53
|
- (void) sendPluginError: (NSString*) errorMessage :(CDVInvokedUrlCommand*)command;
|
|
52
54
|
- (void) handlePluginException: (NSException*) exception :(CDVInvokedUrlCommand*)command;
|
|
@@ -27,5 +27,6 @@
|
|
|
27
27
|
- (void) getLocationAccuracyAuthorization: (CDVInvokedUrlCommand*)command;
|
|
28
28
|
- (void) requestLocationAuthorization: (CDVInvokedUrlCommand*)command;
|
|
29
29
|
- (void) requestTemporaryFullAccuracyAuthorization: (CDVInvokedUrlCommand*)command;
|
|
30
|
+
- (void) isCompassAvailable: (CDVInvokedUrlCommand*)command;
|
|
30
31
|
|
|
31
32
|
@end
|
|
@@ -154,6 +154,19 @@ static NSString*const LOG_TAG = @"Diagnostic_Location[native]";
|
|
|
154
154
|
}];
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
- (void) isCompassAvailable: (CDVInvokedUrlCommand*)command
|
|
158
|
+
{
|
|
159
|
+
[self.commandDelegate runInBackground:^{
|
|
160
|
+
@try {
|
|
161
|
+
bool isAvailable = [CLLocationManager headingAvailable];
|
|
162
|
+
[diagnostic sendPluginResultBool:isAvailable :command];
|
|
163
|
+
}
|
|
164
|
+
@catch (NSException *exception) {
|
|
165
|
+
[diagnostic handlePluginException:exception :command];
|
|
166
|
+
}
|
|
167
|
+
}];
|
|
168
|
+
}
|
|
169
|
+
|
|
157
170
|
/********************************/
|
|
158
171
|
#pragma mark - Internals
|
|
159
172
|
/********************************/
|
|
@@ -10,10 +10,11 @@
|
|
|
10
10
|
#import <Cordova/CDVPlugin.h>
|
|
11
11
|
#import "Diagnostic.h"
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
@interface Diagnostic_Wifi : CDVPlugin
|
|
13
|
+
@interface Diagnostic_Wifi : CDVPlugin <NSNetServiceDelegate>
|
|
15
14
|
|
|
16
15
|
- (void) isWifiAvailable: (CDVInvokedUrlCommand*)command;
|
|
17
16
|
- (void) isWifiEnabled: (CDVInvokedUrlCommand*)command;
|
|
17
|
+
- (void) requestLocalNetworkAuthorization: (CDVInvokedUrlCommand*)command;
|
|
18
|
+
- (void) getLocalNetworkAuthorizationStatus: (CDVInvokedUrlCommand*)command;
|
|
18
19
|
|
|
19
20
|
@end
|
|
@@ -11,8 +11,30 @@
|
|
|
11
11
|
#import <arpa/inet.h> // For AF_INET, etc.
|
|
12
12
|
#import <ifaddrs.h> // For getifaddrs()
|
|
13
13
|
#import <net/if.h> // For IFF_LOOPBACK
|
|
14
|
+
#import <Network/Network.h>
|
|
15
|
+
#import <Network/browser.h>
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
// UserDefaults key for caching local network permission
|
|
18
|
+
static NSString*const kLocalNetworkPermissionKey = @"Diagnostic_LocalNetworkPermission";
|
|
19
|
+
|
|
20
|
+
typedef NS_ENUM(NSInteger, LocalNetworkPermissionState) {
|
|
21
|
+
LocalNetworkPermissionStateUnknown = 0,
|
|
22
|
+
LocalNetworkPermissionStateGranted = 1,
|
|
23
|
+
LocalNetworkPermissionStateDenied = -1,
|
|
24
|
+
};
|
|
25
|
+
@implementation Diagnostic_Wifi {
|
|
26
|
+
nw_browser_t _browser;
|
|
27
|
+
NSNetService *_netService;
|
|
28
|
+
// Completion callbacks stored as CDV callbacks (we'll send results to all when done)
|
|
29
|
+
NSMutableArray<CDVInvokedUrlCommand*> *_localNetworkCommands;
|
|
30
|
+
NSTimer* _localNetworkTimer;
|
|
31
|
+
|
|
32
|
+
// If we have a cached granted/denied value, fall through to the normal path which will verify current status
|
|
33
|
+
// (this may trigger a prompt only if requestLocalNetworkAuthorization was previously called).
|
|
34
|
+
BOOL _isPublishing;
|
|
35
|
+
|
|
36
|
+
BOOL _isRequesting;
|
|
37
|
+
}
|
|
16
38
|
|
|
17
39
|
// Internal reference to Diagnostic singleton instance
|
|
18
40
|
static Diagnostic* diagnostic;
|
|
@@ -25,10 +47,242 @@ static NSString*const LOG_TAG = @"Diagnostic_Wifi[native]";
|
|
|
25
47
|
[super pluginInitialize];
|
|
26
48
|
|
|
27
49
|
diagnostic = [Diagnostic getInstance];
|
|
50
|
+
// initialize commands array
|
|
51
|
+
_localNetworkCommands = [NSMutableArray new];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**************************************/
|
|
55
|
+
#pragma mark - Local Network Plugin API
|
|
56
|
+
/**************************************/
|
|
57
|
+
|
|
58
|
+
- (void) getLocalNetworkAuthorizationStatus: (CDVInvokedUrlCommand*)command
|
|
59
|
+
{
|
|
60
|
+
[self.commandDelegate runInBackground:^{
|
|
61
|
+
@try {
|
|
62
|
+
|
|
63
|
+
// Read cached permission state first
|
|
64
|
+
NSInteger cached = [[NSUserDefaults standardUserDefaults] integerForKey:kLocalNetworkPermissionKey];
|
|
65
|
+
LocalNetworkPermissionState state = (LocalNetworkPermissionState)cached;
|
|
66
|
+
|
|
67
|
+
if (state == LocalNetworkPermissionStateUnknown) {
|
|
68
|
+
// If unknown, do not attempt to start browsing/publishing (that would trigger the system prompt).
|
|
69
|
+
// respond with NO (unauthorized) when never requested.
|
|
70
|
+
[diagnostic sendPluginResultInt:LocalNetworkPermissionStateUnknown :command];
|
|
71
|
+
[diagnostic logDebug:@"Local network permission status is NOT_REQUESTED"];
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Store command so we can send the result later
|
|
76
|
+
@synchronized(self->_localNetworkCommands) {
|
|
77
|
+
[self->_localNetworkCommands addObject:command];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if(self->_isRequesting){
|
|
81
|
+
// A request is already in progress so await the result
|
|
82
|
+
[diagnostic logDebug:@"A request is already in progress, will return result when done"];
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Create parameters, and allow browsing over peer-to-peer link.
|
|
87
|
+
if (@available(iOS 14.0, *)) {
|
|
88
|
+
// Create parameters, and allow browsing over peer-to-peer link.
|
|
89
|
+
nw_parameters_t parameters = nw_parameters_create_secure_tcp(NW_PARAMETERS_DISABLE_PROTOCOL, NW_PARAMETERS_DEFAULT_CONFIGURATION);
|
|
90
|
+
nw_parameters_set_include_peer_to_peer(parameters, true);
|
|
91
|
+
|
|
92
|
+
// Browse for a custom service type.
|
|
93
|
+
nw_browse_descriptor_t descriptor =
|
|
94
|
+
nw_browse_descriptor_create_bonjour_service("_bonjour._tcp", NULL);
|
|
95
|
+
self->_browser = nw_browser_create(descriptor, parameters);
|
|
96
|
+
|
|
97
|
+
nw_browser_set_queue(self->_browser, dispatch_get_main_queue());
|
|
98
|
+
|
|
99
|
+
self->_netService = [[NSNetService alloc] initWithDomain:@"local." type:@"_lnp._tcp." name:@"LocalNetworkPrivacy" port:1100];
|
|
100
|
+
|
|
101
|
+
self->_isRequesting = YES;
|
|
102
|
+
self->_isPublishing = NO;
|
|
103
|
+
|
|
104
|
+
[diagnostic logDebug:@"Starting local network permission status check"];
|
|
105
|
+
// Start the browsing/publish flow on the main queue immediately and create a single-shot timeout.
|
|
106
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
107
|
+
__weak __typeof__(self) weakSelf = self;
|
|
108
|
+
|
|
109
|
+
__strong __typeof__(weakSelf) strongSelf = weakSelf;
|
|
110
|
+
if (!strongSelf) return;
|
|
111
|
+
|
|
112
|
+
// Ensure we only start once for this check
|
|
113
|
+
if (strongSelf->_isPublishing) {
|
|
114
|
+
[diagnostic logDebug:@"Local network permission request already publishing, skipping start"];
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
strongSelf->_isPublishing = YES;
|
|
119
|
+
strongSelf->_netService.delegate = strongSelf;
|
|
120
|
+
|
|
121
|
+
// Install a state handler so the browser emits state changes (silences the warning about missing handlers)
|
|
122
|
+
if (strongSelf->_browser) {
|
|
123
|
+
nw_browser_set_state_changed_handler(strongSelf->_browser, ^(nw_browser_state_t newState, nw_error_t error) {
|
|
124
|
+
switch (newState) {
|
|
125
|
+
case nw_browser_state_failed:
|
|
126
|
+
if (error) {
|
|
127
|
+
nw_error_domain_t errorDomain = nw_error_get_error_domain(error);
|
|
128
|
+
[diagnostic logDebug:[NSString stringWithFormat:@"Browser failed (status check): domain=%d", (int)errorDomain]];
|
|
129
|
+
}
|
|
130
|
+
break;
|
|
131
|
+
case nw_browser_state_ready:
|
|
132
|
+
case nw_browser_state_cancelled:
|
|
133
|
+
case nw_browser_state_waiting:
|
|
134
|
+
default:
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
nw_browser_start(strongSelf->_browser);
|
|
140
|
+
} else {
|
|
141
|
+
[diagnostic logDebug:@"Attempted to start browser but browser is null"];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
[strongSelf->_netService publish];
|
|
145
|
+
[strongSelf->_netService scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
|
|
146
|
+
|
|
147
|
+
// Set a single-shot timeout to consider the permission request failed
|
|
148
|
+
strongSelf->_localNetworkTimer = [NSTimer scheduledTimerWithTimeInterval:2.0
|
|
149
|
+
repeats:NO
|
|
150
|
+
block:^(NSTimer * _Nonnull timer) {
|
|
151
|
+
__strong __typeof__(weakSelf) innerSelf = weakSelf;
|
|
152
|
+
if (!innerSelf) return;
|
|
153
|
+
|
|
154
|
+
[diagnostic logDebug:@"Local network permission request timed out"];
|
|
155
|
+
[self callLocalNetworkCallbacks:LocalNetworkPermissionStateDenied];
|
|
156
|
+
[innerSelf resetLocalNetwork];
|
|
157
|
+
}];
|
|
158
|
+
});
|
|
159
|
+
}else{
|
|
160
|
+
[diagnostic logDebug:@"iOS version < 14.0, so local network permission is not required"];
|
|
161
|
+
[self callLocalNetworkCallbacks:LocalNetworkPermissionStateGranted];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
@catch (NSException *exception) {
|
|
165
|
+
[diagnostic handlePluginException:exception :command];
|
|
166
|
+
}
|
|
167
|
+
}];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// This code is based on https://stackoverflow.com/a/67758105/2618437 with slight modifications
|
|
171
|
+
- (void) requestLocalNetworkAuthorization: (CDVInvokedUrlCommand*)command
|
|
172
|
+
{
|
|
173
|
+
[self.commandDelegate runInBackground:^{
|
|
174
|
+
@try {
|
|
175
|
+
if(self->_isRequesting){
|
|
176
|
+
// A request is already in progress
|
|
177
|
+
[diagnostic sendPluginError:@"A request is already in progress" :command];
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
self->_isRequesting = YES;
|
|
181
|
+
|
|
182
|
+
// Store command so we can send the result later
|
|
183
|
+
@synchronized(self->_localNetworkCommands) {
|
|
184
|
+
[self->_localNetworkCommands addObject:command];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (@available(iOS 14.0, *)) {
|
|
188
|
+
// Create parameters, and allow browsing over peer-to-peer link.
|
|
189
|
+
nw_parameters_t parameters = nw_parameters_create_secure_tcp(NW_PARAMETERS_DISABLE_PROTOCOL, NW_PARAMETERS_DEFAULT_CONFIGURATION);
|
|
190
|
+
nw_parameters_set_include_peer_to_peer(parameters, true);
|
|
191
|
+
|
|
192
|
+
// Browse for a custom service type.
|
|
193
|
+
nw_browse_descriptor_t descriptor =
|
|
194
|
+
nw_browse_descriptor_create_bonjour_service("_bonjour._tcp", NULL);
|
|
195
|
+
self->_browser = nw_browser_create(descriptor, parameters);
|
|
196
|
+
|
|
197
|
+
nw_browser_set_queue(self->_browser, dispatch_get_main_queue());
|
|
198
|
+
|
|
199
|
+
__weak __typeof__(self) weakSelf = self;
|
|
200
|
+
nw_browser_set_state_changed_handler(self->_browser, ^(nw_browser_state_t newState, nw_error_t error) {
|
|
201
|
+
__strong __typeof__(weakSelf) strongSelf = weakSelf;
|
|
202
|
+
switch (newState) {
|
|
203
|
+
case nw_browser_state_failed:
|
|
204
|
+
if (error) {
|
|
205
|
+
nw_error_domain_t errorDomain = nw_error_get_error_domain(error);
|
|
206
|
+
[diagnostic logDebug:[NSString stringWithFormat:@"Browser failed: domain=%d", (int)errorDomain]];
|
|
207
|
+
}
|
|
208
|
+
break;
|
|
209
|
+
case nw_browser_state_ready:
|
|
210
|
+
case nw_browser_state_cancelled:
|
|
211
|
+
break;
|
|
212
|
+
case nw_browser_state_waiting:
|
|
213
|
+
if (error) {
|
|
214
|
+
nw_error_domain_t errorDomain = nw_error_get_error_domain(error);
|
|
215
|
+
[diagnostic logDebug:[NSString stringWithFormat:@"Local network permission has been denied: domain=%d", (int)errorDomain]];
|
|
216
|
+
} else {
|
|
217
|
+
[diagnostic logDebug:@"Local network permission has been denied"];
|
|
218
|
+
}
|
|
219
|
+
[strongSelf resetLocalNetwork];
|
|
220
|
+
// cache denied
|
|
221
|
+
[[NSUserDefaults standardUserDefaults] setInteger:LocalNetworkPermissionStateDenied forKey:kLocalNetworkPermissionKey];
|
|
222
|
+
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
223
|
+
// send false result to all waiting commands
|
|
224
|
+
[self callLocalNetworkCallbacks:LocalNetworkPermissionStateDenied];
|
|
225
|
+
break;
|
|
226
|
+
default:
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
self->_netService = [[NSNetService alloc] initWithDomain:@"local." type:@"_lnp._tcp." name:@"LocalNetworkPrivacy" port:1100];
|
|
232
|
+
self->_netService.delegate = self;
|
|
233
|
+
|
|
234
|
+
// Start browsing on main queue
|
|
235
|
+
nw_browser_start(self->_browser);
|
|
236
|
+
[self->_netService publish];
|
|
237
|
+
// the netService needs to be scheduled on a run loop, in this case the main runloop
|
|
238
|
+
[self->_netService scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
|
|
239
|
+
}else{
|
|
240
|
+
// iOS version < 14.0, so local network permission is not required
|
|
241
|
+
[self callLocalNetworkCallbacks:LocalNetworkPermissionStateGranted];
|
|
242
|
+
}
|
|
243
|
+
} @catch (NSException *exception) {
|
|
244
|
+
[diagnostic handlePluginException:exception :command];
|
|
245
|
+
}
|
|
246
|
+
}];
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
- (void) resetLocalNetwork
|
|
250
|
+
{
|
|
251
|
+
[diagnostic logDebug:@"resetting"];
|
|
252
|
+
// stop the timer if active so it doesn't keep firing
|
|
253
|
+
if (_localNetworkTimer) {
|
|
254
|
+
[_localNetworkTimer invalidate];
|
|
255
|
+
_localNetworkTimer = nil;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// reset state flags
|
|
259
|
+
self->_isPublishing = NO;
|
|
260
|
+
self->_isRequesting = NO;
|
|
261
|
+
|
|
262
|
+
if (_browser) {
|
|
263
|
+
if (@available(iOS 13.0, *)) {
|
|
264
|
+
nw_browser_cancel(_browser);
|
|
265
|
+
}
|
|
266
|
+
_browser = nil;
|
|
267
|
+
}
|
|
268
|
+
if (_netService) {
|
|
269
|
+
[_netService stop];
|
|
270
|
+
_netService = nil;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
- (void) callLocalNetworkCallbacks:(LocalNetworkPermissionState)result
|
|
275
|
+
{
|
|
276
|
+
@synchronized(self->_localNetworkCommands) {
|
|
277
|
+
for (CDVInvokedUrlCommand *c in self->_localNetworkCommands) {
|
|
278
|
+
[diagnostic sendPluginResultInt:(int)result :c];
|
|
279
|
+
}
|
|
280
|
+
[self->_localNetworkCommands removeAllObjects];
|
|
281
|
+
}
|
|
28
282
|
}
|
|
29
283
|
|
|
30
284
|
/********************************/
|
|
31
|
-
#pragma mark - Plugin API
|
|
285
|
+
#pragma mark - Wifi Plugin API
|
|
32
286
|
/********************************/
|
|
33
287
|
|
|
34
288
|
- (void) isWifiAvailable: (CDVInvokedUrlCommand*)command
|
|
@@ -105,4 +359,23 @@ static NSString*const LOG_TAG = @"Diagnostic_Wifi[native]";
|
|
|
105
359
|
}
|
|
106
360
|
|
|
107
361
|
|
|
362
|
+
/********************************/
|
|
363
|
+
#pragma mark - NetServiceDelegate
|
|
364
|
+
/********************************/
|
|
365
|
+
|
|
366
|
+
- (void)netServiceDidPublish:(NSNetService *)sender {
|
|
367
|
+
[diagnostic logDebug:@"netServiceDidPublish: Local network permission has been granted"];
|
|
368
|
+
[self resetLocalNetwork];
|
|
369
|
+
if (_localNetworkTimer) {
|
|
370
|
+
[_localNetworkTimer invalidate];
|
|
371
|
+
_localNetworkTimer = nil;
|
|
372
|
+
}
|
|
373
|
+
_isPublishing = NO;
|
|
374
|
+
|
|
375
|
+
// cache granted
|
|
376
|
+
[[NSUserDefaults standardUserDefaults] setInteger:LocalNetworkPermissionStateGranted forKey:kLocalNetworkPermissionKey];
|
|
377
|
+
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
378
|
+
|
|
379
|
+
[self callLocalNetworkCallbacks:LocalNetworkPermissionStateGranted];
|
|
380
|
+
}
|
|
108
381
|
@end
|
|
@@ -825,6 +825,22 @@ var Diagnostic = (function(){
|
|
|
825
825
|
}
|
|
826
826
|
};
|
|
827
827
|
|
|
828
|
+
/**
|
|
829
|
+
* Checks if compass is available on the device for use by the app.
|
|
830
|
+
*
|
|
831
|
+
* @param {Function} successCallback - The callback which will be called when operation is successful.
|
|
832
|
+
* This callback function is passed a single boolean parameter which is TRUE if compass is available for use.
|
|
833
|
+
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
|
|
834
|
+
* This callback function is passed a single string parameter containing the error message.
|
|
835
|
+
*/
|
|
836
|
+
Diagnostic.isCompassAvailable = function(successCallback, errorCallback) {
|
|
837
|
+
if(cordova.plugins.diagnostic.location){
|
|
838
|
+
cordova.plugins.diagnostic.location.isCompassAvailable.apply(this, arguments);
|
|
839
|
+
}else{
|
|
840
|
+
throw "Diagnostic Location module is not installed";
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
|
|
828
844
|
/************
|
|
829
845
|
* WiFi *
|
|
830
846
|
************/
|
|
@@ -319,6 +319,22 @@ var Diagnostic_Location = (function(){
|
|
|
319
319
|
]);
|
|
320
320
|
};
|
|
321
321
|
|
|
322
|
+
/**
|
|
323
|
+
* Checks if compass is available on the device for use by the app.
|
|
324
|
+
*
|
|
325
|
+
* @param {Function} successCallback - The callback which will be called when operation is successful.
|
|
326
|
+
* This callback function is passed a single boolean parameter which is TRUE if compass is available for use.
|
|
327
|
+
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
|
|
328
|
+
* This callback function is passed a single string parameter containing the error message.
|
|
329
|
+
*/
|
|
330
|
+
Diagnostic_Location.isCompassAvailable = function(successCallback, errorCallback) {
|
|
331
|
+
return cordova.exec(Diagnostic._ensureBoolean(successCallback),
|
|
332
|
+
errorCallback,
|
|
333
|
+
'Diagnostic_Location',
|
|
334
|
+
'isCompassAvailable',
|
|
335
|
+
[]);
|
|
336
|
+
};
|
|
337
|
+
|
|
322
338
|
return Diagnostic_Location;
|
|
323
339
|
});
|
|
324
340
|
module.exports = new Diagnostic_Location();
|
package/www/ios/diagnostic.js
CHANGED
|
@@ -339,6 +339,22 @@ var Diagnostic = (function(){
|
|
|
339
339
|
}
|
|
340
340
|
};
|
|
341
341
|
|
|
342
|
+
/**
|
|
343
|
+
* Checks if compass is available on the device for use by the app.
|
|
344
|
+
*
|
|
345
|
+
* @param {Function} successCallback - The callback which will be called when operation is successful.
|
|
346
|
+
* This callback function is passed a single boolean parameter which is TRUE if compass is available for use.
|
|
347
|
+
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
|
|
348
|
+
* This callback function is passed a single string parameter containing the error message.
|
|
349
|
+
*/
|
|
350
|
+
Diagnostic.isCompassAvailable = function(successCallback, errorCallback) {
|
|
351
|
+
if(cordova.plugins.diagnostic.location){
|
|
352
|
+
cordova.plugins.diagnostic.location.isCompassAvailable.apply(this, arguments);
|
|
353
|
+
}else{
|
|
354
|
+
throw "Diagnostic Location module is not installed";
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
|
|
342
358
|
/**
|
|
343
359
|
* Requests location authorization for the application.
|
|
344
360
|
* Authorization can be requested to use location either "when in use" (only in foreground) or "always" (foreground and background).
|
|
@@ -631,6 +647,62 @@ var Diagnostic = (function(){
|
|
|
631
647
|
}
|
|
632
648
|
};
|
|
633
649
|
|
|
650
|
+
/**
|
|
651
|
+
* Checks if the app is authorized to use Local Network.
|
|
652
|
+
* On iOS 14+ this returns true if the user has authorized the app to access devices on the local network.
|
|
653
|
+
* On iOS versions prior to 14, this always returns true as no authorization is required.
|
|
654
|
+
*
|
|
655
|
+
* @param {Function} successCallback - The callback which will be called when operation is successful.
|
|
656
|
+
* This callback function is passed a single boolean parameter which is TRUE if the app is authorized to use Local Network.
|
|
657
|
+
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
|
|
658
|
+
* This callback function is passed a single string parameter containing the error message.
|
|
659
|
+
*/
|
|
660
|
+
Diagnostic.isLocalNetworkAuthorized = function(successCallback, errorCallback) {
|
|
661
|
+
if(cordova.plugins.diagnostic.wifi){
|
|
662
|
+
cordova.plugins.diagnostic.wifi.isLocalNetworkAuthorized.apply(this, arguments);
|
|
663
|
+
}else{
|
|
664
|
+
throw "Diagnostic Wifi module is not installed";
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Returns the app's Local Network authorization status.
|
|
670
|
+
* On iOS 14+ this returns one of the values in Diagnostic.permissionStatus: NOT_REQUESTED, GRANTED, DENIED_ALWAYS.
|
|
671
|
+
* On iOS versions prior to 14, this always returns GRANTED as no authorization is required.
|
|
672
|
+
*
|
|
673
|
+
* @param {Function} successCallback - The callback which will be called when operation is successful.
|
|
674
|
+
* This callback function is passed a single string parameter which is one of the values in Diagnostic.permissionStatus:
|
|
675
|
+
* NOT_REQUESTED, GRANTED, DENIED_ALWAYS.
|
|
676
|
+
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
|
|
677
|
+
* This callback function is passed a single string parameter containing the error message.
|
|
678
|
+
*/
|
|
679
|
+
Diagnostic.getLocalNetworkAuthorizationStatus = function(successCallback, errorCallback) {
|
|
680
|
+
if(cordova.plugins.diagnostic.wifi){
|
|
681
|
+
cordova.plugins.diagnostic.wifi.getLocalNetworkAuthorizationStatus.apply(this, arguments);
|
|
682
|
+
}else{
|
|
683
|
+
throw "Diagnostic Wifi module is not installed";
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Requests the user to authorize the app to use Local Network.
|
|
689
|
+
* On iOS 14+ this will prompt the user to authorize the app to access devices on the local network.
|
|
690
|
+
* On iOS versions prior to 14, this does nothing as no authorization is required and will return success.
|
|
691
|
+
*
|
|
692
|
+
* @param {Function} successCallback - The callback which will be called when operation is successful.
|
|
693
|
+
* This callback function is passed a single string parameter which is one of the values in Diagnostic.permissionStatus:
|
|
694
|
+
* NOT_REQUESTED, GRANTED, DENIED_ALWAYS.
|
|
695
|
+
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
|
|
696
|
+
* This callback function is passed a single string parameter containing the error message.
|
|
697
|
+
*/
|
|
698
|
+
Diagnostic.requestLocalNetworkAuthorization = function(successCallback, errorCallback) {
|
|
699
|
+
if(cordova.plugins.diagnostic.wifi){
|
|
700
|
+
cordova.plugins.diagnostic.wifi.requestLocalNetworkAuthorization.apply(this, arguments);
|
|
701
|
+
}else{
|
|
702
|
+
throw "Diagnostic Wifi module is not installed";
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
|
|
634
706
|
/***************
|
|
635
707
|
* Bluetooth *
|
|
636
708
|
***************/
|
|
@@ -231,6 +231,22 @@ var Diagnostic_Location = (function(){
|
|
|
231
231
|
Diagnostic_Location._onLocationAccuracyAuthorizationChange = successCallback || function(){};
|
|
232
232
|
};
|
|
233
233
|
|
|
234
|
+
/**
|
|
235
|
+
* Checks if compass is available on the device for use by the app.
|
|
236
|
+
*
|
|
237
|
+
* @param {Function} successCallback - The callback which will be called when operation is successful.
|
|
238
|
+
* This callback function is passed a single boolean parameter which is TRUE if compass is available for use.
|
|
239
|
+
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
|
|
240
|
+
* This callback function is passed a single string parameter containing the error message.
|
|
241
|
+
*/
|
|
242
|
+
Diagnostic_Location.isCompassAvailable = function(successCallback, errorCallback) {
|
|
243
|
+
return cordova.exec(Diagnostic._ensureBoolean(successCallback),
|
|
244
|
+
errorCallback,
|
|
245
|
+
'Diagnostic_Location',
|
|
246
|
+
'isCompassAvailable',
|
|
247
|
+
[]);
|
|
248
|
+
};
|
|
249
|
+
|
|
234
250
|
return Diagnostic_Location;
|
|
235
251
|
});
|
|
236
252
|
module.exports = new Diagnostic_Location();
|
|
@@ -27,6 +27,22 @@ var Diagnostic_Wifi = (function(){
|
|
|
27
27
|
* Internal functions
|
|
28
28
|
*
|
|
29
29
|
********************/
|
|
30
|
+
function processLocalNetworkStatus(nativeStatus, successCallback) {
|
|
31
|
+
let status;
|
|
32
|
+
switch (nativeStatus) {
|
|
33
|
+
case 1: // LocalNetworkPermissionStateGranted
|
|
34
|
+
status = Diagnostic.permissionStatus.GRANTED;
|
|
35
|
+
break;
|
|
36
|
+
case -1: // LocalNetworkPermissionStateDenied
|
|
37
|
+
status = Diagnostic.permissionStatus.DENIED_ALWAYS;
|
|
38
|
+
break;
|
|
39
|
+
case 0: // LocalNetworkPermissionStateUnknown
|
|
40
|
+
default:
|
|
41
|
+
status = Diagnostic.permissionStatus.NOT_REQUESTED;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
successCallback(status);
|
|
45
|
+
}
|
|
30
46
|
|
|
31
47
|
/*****************************
|
|
32
48
|
*
|
|
@@ -75,6 +91,70 @@ var Diagnostic_Wifi = (function(){
|
|
|
75
91
|
[]);
|
|
76
92
|
};
|
|
77
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Checks if the app is authorized to use Local Network.
|
|
96
|
+
* On iOS 14+ this returns true if the user has authorized the app to access devices on the local network.
|
|
97
|
+
* On iOS versions prior to 14, this always returns true as no authorization is required.
|
|
98
|
+
*
|
|
99
|
+
* @param {Function} successCallback - The callback which will be called when operation is successful.
|
|
100
|
+
* This callback function is passed a single boolean parameter which is TRUE if the app is authorized to use Local Network.
|
|
101
|
+
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
|
|
102
|
+
* This callback function is passed a single string parameter containing the error message.
|
|
103
|
+
*/
|
|
104
|
+
Diagnostic_Wifi.isLocalNetworkAuthorized = function(successCallback, errorCallback) {
|
|
105
|
+
return cordova.exec(function(status) {
|
|
106
|
+
var authorized = (status === 1); // LocalNetworkPermissionStateAuthorized
|
|
107
|
+
successCallback(authorized);
|
|
108
|
+
},
|
|
109
|
+
errorCallback,
|
|
110
|
+
'Diagnostic_Wifi',
|
|
111
|
+
'getLocalNetworkAuthorizationStatus',
|
|
112
|
+
[]);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Returns the app's Local Network authorization status.
|
|
118
|
+
* On iOS 14+ this returns one of the values in Diagnostic.permissionStatus: NOT_REQUESTED, GRANTED, DENIED_ALWAYS.
|
|
119
|
+
* On iOS versions prior to 14, this always returns GRANTED as no authorization is required.
|
|
120
|
+
*
|
|
121
|
+
* @param {Function} successCallback - The callback which will be called when operation is successful.
|
|
122
|
+
* This callback function is passed a single string parameter which is one of the values in Diagnostic.permissionStatus:
|
|
123
|
+
* NOT_REQUESTED, GRANTED, DENIED_ALWAYS.
|
|
124
|
+
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
|
|
125
|
+
* This callback function is passed a single string parameter containing the error message.
|
|
126
|
+
*/
|
|
127
|
+
Diagnostic_Wifi.getLocalNetworkAuthorizationStatus = function(successCallback, errorCallback) {
|
|
128
|
+
return cordova.exec(function(nativeStatus) {
|
|
129
|
+
processLocalNetworkStatus(nativeStatus, successCallback);
|
|
130
|
+
},
|
|
131
|
+
errorCallback,
|
|
132
|
+
'Diagnostic_Wifi',
|
|
133
|
+
'getLocalNetworkAuthorizationStatus',
|
|
134
|
+
[]);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Requests the user to authorize the app to use Local Network.
|
|
139
|
+
* On iOS 14+ this will prompt the user to authorize the app to access devices on the local network.
|
|
140
|
+
* On iOS versions prior to 14, this does nothing as no authorization is required and will return success.
|
|
141
|
+
*
|
|
142
|
+
* @param {Function} successCallback - The callback which will be called when operation is successful.
|
|
143
|
+
* This callback function is passed a single string parameter which is one of the values in Diagnostic.permissionStatus:
|
|
144
|
+
* NOT_REQUESTED, GRANTED, DENIED_ALWAYS.
|
|
145
|
+
* @param {Function} errorCallback - The callback which will be called when operation encounters an error.
|
|
146
|
+
* This callback function is passed a single string parameter containing the error message.
|
|
147
|
+
*/
|
|
148
|
+
Diagnostic_Wifi.requestLocalNetworkAuthorization = function(successCallback, errorCallback) {
|
|
149
|
+
return cordova.exec(function(nativeStatus) {
|
|
150
|
+
processLocalNetworkStatus(nativeStatus, successCallback);
|
|
151
|
+
},
|
|
152
|
+
errorCallback,
|
|
153
|
+
'Diagnostic_Wifi',
|
|
154
|
+
'requestLocalNetworkAuthorization',
|
|
155
|
+
[]);
|
|
156
|
+
};
|
|
157
|
+
|
|
78
158
|
return Diagnostic_Wifi;
|
|
79
159
|
});
|
|
80
160
|
module.exports = new Diagnostic_Wifi();
|