UNPKG

22.5 kBTypeScriptView Raw
1import { Observable } from 'rxjs/Observable';
2export interface Beacon {
3 /**
4 * The physical device's identifier.
5 */
6 uuid: string;
7 /**
8 * The beacon's major identifier number.
9 */
10 major: number;
11 /**
12 * The beacon's major identifier number.
13 */
14 minor: number;
15 /**
16 * The proximity of the beacon relative to the phone.
17 *
18 * Possible options are:
19 * ProximityImmediate
20 * ProximityNear
21 * ProximityFar
22 * ProximityUnknown
23 */
24 proximity: 'ProximityImmediate' | 'ProximityNear' | 'ProximityFar' | 'ProximityUnknown';
25 /**
26 * Transmission Power of the beacon. A constant emitted by the beacon which indicates what's the expected RSSI at a distance of 1 meter to the beacon.
27 */
28 tx: number;
29 /**
30 * Received Signal Strength Indicator. The strength of the beacon's signal when it reaches the device.
31 * RSSI ranges from aprox -26 (a few inches) to -100 (40-50 m distance).
32 */
33 rssi: number;
34 /**
35 * The accuracy of the ranging.
36 */
37 accuracy: number;
38}
39export interface BeaconRegion {
40 /**
41 * A unique identifier for this region.
42 */
43 identifier: string;
44 /**
45 * The the beacon identifier the device will "watch" for. Many beacons can share the same uuid.
46 */
47 uuid: string;
48 /**
49 * The beacon's major identifier number. Optional, of nothing is supplied
50 * the plugin will treat it as a wildcard.
51 */
52 major?: number;
53 /**
54 * The beacon's minor identifier number. Optional, of nothing is supplied
55 * the plugin will treat it as a wildcard.
56 */
57 minor?: number;
58 /**
59 * If set to true the device will scan for beacons and determine region state anytime
60 * the device's screen is turned on or off. Useful for debugging.
61 */
62 notifyEntryStateOnDisplay?: boolean;
63}
64export interface CircularRegion {
65 /**
66 * A unique identifier for this region.
67 */
68 identifier: string;
69 /**
70 * The latitude of this region.
71 */
72 latitude: number;
73 /**
74 * The longitude of this region.
75 */
76 longitude: number;
77 /**
78 * The radius of the geofence for this region.
79 */
80 radius: number;
81}
82export declare type Region = BeaconRegion | CircularRegion;
83export interface IBeaconPluginResult {
84 /**
85 * The name of the delegate function that produced the PluginResult object.
86 */
87 eventType: string;
88 /**
89 * The region that triggered the event.
90 */
91 region: Region;
92 /**
93 * An array of beacon objects
94 */
95 beacons: Beacon[];
96 /**
97 * The status of the location permission for iOS.
98 */
99 authorizationStatus: string;
100 /**
101 * The state of the phone in relation to the region. Inside/outside for example.
102 */
103 state: 'CLRegionStateInside' | 'CLRegionStateOutside';
104 /**
105 * Error message, used only with monitoringDidFailForRegionWithError delegate.
106 */
107 error: string;
108}
109export interface IBeaconDelegate {
110 /**
111 * An observable that publishes information about the location permission authorization status.
112 *
113 * @returns {Observable<string>} Returns a string.
114 */
115 didChangeAuthorizationStatus(): Observable<string>;
116 /**
117 * An Observable that publishes event data to it's subscribers
118 * when the native layer is able to determine the device's state.
119 *
120 * This event is called when the phone begins starts monitoring,
121 * when requestStateForRegion is called, etc.
122 *
123 * @returns {Observable<IBeaconPluginResult>} Returns a IBeaconPluginResult object with information about the event, region, and beacon(s).
124 */
125 didDetermineStateForRegion(): Observable<IBeaconPluginResult>;
126 /**
127 * An Observable that publishes event data to it's subscribers
128 * when the phone enters a region that it was asked to monitor.
129 *
130 * If the user has given the app Always-Location permission, this function
131 * will be called even when the app is not running on iOS.
132 * The app will run silently in the background for a small amount of time.
133 *
134 * @returns {Observable<IBeaconPluginResult>} Returns a IBeaconPluginResult object with information about the event, region, and beacon(s).
135 */
136 didEnterRegion(): Observable<IBeaconPluginResult>;
137 /**
138 * An Observable that publishes event data to it's subscribers
139 * when the phone exits a region that it was asked to monitor.
140 *
141 * If the user has given the app Always-Location permission, this function
142 * will be called even when the app is not running on iOS.
143 * The app will run silently in the background for a small amount of time.
144 *
145 * @returns {Observable<IBeaconPluginResult>} Returns a IBeaconPluginResult object with information about the event, region, and beacon(s).
146 */
147 didExitRegion(): Observable<IBeaconPluginResult>;
148 /**
149 * An Observable that publishes event data to it's subscribers
150 * each time that the device ranges beacons. Modern Android and iOS devices range
151 * aproximately once per second.
152 *
153 * @returns {Observable<IBeaconPluginResult>} Returns a IBeaconPluginResult object with information about the event, region, and beacon(s).
154 */
155 didRangeBeaconsInRegion(): Observable<IBeaconPluginResult>;
156 /**
157 * An Observable that publishes event data to it's subscribers
158 * when the device begins monitoring a region.
159 *
160 * @returns {Observable<IBeaconPluginResult>} Returns a IBeaconPluginResult object with information about the event, region, and beacon(s).
161 */
162 didStartMonitoringForRegion(): Observable<IBeaconPluginResult>;
163 /**
164 * An Observable that publishes event data to it's subscribers
165 * when the device fails to monitor a region.
166 *
167 * @returns {Observable<IBeaconPluginResult>} Returns a IBeaconPluginResult object with information about the event, region, and beacon(s).
168 */
169 monitoringDidFailForRegionWithError(): Observable<IBeaconPluginResult>;
170 /**
171 * An Observable that publishes event data to it's subscribers
172 * when the device begins advertising as an iBeacon.
173 *
174 * @returns {Observable<IBeaconPluginResult>} Returns a IBeaconPluginResult object with information about the event, region, and beacon(s).
175 */
176 peripheralManagerDidStartAdvertising(): Observable<IBeaconPluginResult>;
177 /**
178 * An Observable that publishes event data to it's subscribers
179 * when the state of the peripheral manager's state updates.
180 *
181 *
182 * @returns {Observable<IBeaconPluginResult>} Returns a IBeaconPluginResult object with information about the event, region, and beacon(s).
183 */
184 peripheralManagerDidUpdateState(): Observable<IBeaconPluginResult>;
185}
186/**
187 * @name IBeacon
188 * @description
189 * This plugin provides functions for working with iBeacons.
190 *
191 * The plugin's API closely mimics the one exposed through the [CLLocationManager](https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html) introduced in iOS 7.
192 *
193 * @usage
194 *
195 * ```typescript
196 * import { IBeacon } from 'ionic-native';
197 *
198 *
199 * // Request permission to use location on iOS
200 * IBeacon.requestAlwaysAuthorization();
201 * // create a new delegate and register it with the native layer
202 * let delegate = IBeacon.Delegate();
203 *
204 * // Subscribe to some of the delegate's event handlers
205 * delegate.didRangeBeaconsInRegion()
206 * .subscribe(
207 * data => console.log('didRangeBeaconsInRegion: ', data),
208 * error => console.error();
209 * );
210 * delegate.didStartMonitoringForRegion()
211 * .subscribe(
212 * data => console.log('didStartMonitoringForRegion: ', data),
213 * error => console.error();
214 * );
215 * delegate.didEnterRegion()
216 * .subscribe(
217 * data => {
218 * console.log('didEnterRegion: ', data);
219 * }
220 * );
221 *
222 * let beaconRegion = IBeacon.BeaconRegion('deskBeacon','F7826DA6-ASDF-ASDF-8024-BC5B71E0893E');
223 *
224 * IBeacon.startMonitoringForRegion(beaconRegion)
225 * .then(
226 * () => console.log('Native layer recieved the request to monitoring'),
227 * error => console.error('Native layer failed to begin monitoring: ', error)
228 * );
229 * ```
230 * @interfaces
231 * Beacon
232 * BeaconRegion
233 * CircularRegion
234 * IBeaconPluginResult
235 * IBeaconDelegate
236 *
237 */
238export declare class IBeacon {
239 /**
240 * Instances of this class are delegates between the {@link LocationManager} and
241 * the code that consumes the messages generated on in the native layer.
242 *
243 * @returns {IBeaconDelegate} An instance of the type {@type Delegate}.
244 */
245 static Delegate(): IBeaconDelegate;
246 /**
247 * Creates a new BeaconRegion
248 *
249 * @param {String} identifier @see {CLRegion}
250 * @param {String} uuid The proximity ID of the beacon being targeted.
251 * This value must not be blank nor invalid as a UUID.
252 * @param {Number} major The major value that you use to identify one or more beacons.
253 * @param {Number} minor The minor value that you use to identify a specific beacon.
254 * @param {BOOL} notifyEntryStateOnDisplay
255 *
256 * @returns {BeaconRegion} Returns the BeaconRegion that was created
257 */
258 static BeaconRegion(identifer: string, uuid: string, major?: number, minor?: number, notifyEntryStateOnDisplay?: boolean): BeaconRegion;
259 /**
260 * @returns {IBeaconDelegate} Returns the IBeaconDelegate
261 */
262 static getDelegate(): IBeaconDelegate;
263 /**
264 * @param {IBeaconDelegate} delegate An instance of a delegate to register with the native layer.
265 *
266 * @returns {IBeaconDelegate} Returns the IBeaconDelegate
267 */
268 static setDelegate(delegate: IBeaconDelegate): IBeaconDelegate;
269 /**
270 * Signals the native layer that the client side is ready to consume messages.
271 * Readiness here means that it has a {IBeaconDelegate} set by the consumer javascript
272 * code.
273 *
274 * The {LocationManager.setDelegate()} will implicitly call this method as well,
275 * therefore the only case when you have to call this manually is if you don't
276 * wish to specify a {IBeaconDelegate} of yours.
277 *
278 * The purpose of this signaling mechanism is to make the events work when the
279 * app is being woken up by the Operating System to give it a chance to handle
280 * region monitoring events for example.
281 *
282 * If you don't set a {IBeaconDelegate} and don't call this method manually, an error
283 * message get emitted in the native runtime and the DOM as well after a certain
284 * period of time.
285 *
286 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
287 * native layer acknowledged the request and started to send events.
288 */
289 static onDomDelegateReady(): Promise<void>;
290 /**
291 * Determines if bluetooth is switched on, according to the native layer.
292 * @returns {Promise<boolean>} Returns a promise which is resolved with a {Boolean}
293 * indicating whether bluetooth is active.
294 */
295 static isBluetoothEnabled(): Promise<boolean>;
296 /**
297 * Enables Bluetooth using the native Layer. (ANDROID ONLY)
298 *
299 * @returns {Promise<void>} Returns a promise which is resolved when Bluetooth
300 * could be enabled. If not, the promise will be rejected with an error.
301 */
302 static enableBluetooth(): Promise<void>;
303 /**
304 * Disables Bluetooth using the native Layer. (ANDROID ONLY)
305 *
306 * @returns {Promise<void>} Returns a promise which is resolved when Bluetooth
307 * could be enabled. If not, the promise will be rejected with an error.
308 */
309 static disableBluetooth(): Promise<void>;
310 /**
311 * Start monitoring the specified region.
312 *
313 * If a region of the same type with the same identifier is already being
314 * monitored for this application,
315 * it will be removed from monitoring. For circular regions, the region
316 * monitoring service will prioritize
317 * regions by their size, favoring smaller regions over larger regions.
318 *
319 * This is done asynchronously and may not be immediately reflected in monitoredRegions.
320 *
321 * @param {Region} region An instance of {Region} which will be monitored
322 * by the operating system.
323 *
324 * @returns {Promise<string>} Returns a promise which is resolved as soon as the
325 * native layer acknowledged the dispatch of the monitoring request.
326 */
327 static startMonitoringForRegion(region: BeaconRegion): Promise<string>;
328 /**
329 * Stop monitoring the specified region. It is valid to call
330 * stopMonitoringForRegion: for a region that was registered for monitoring
331 * with a different location manager object, during this or previous
332 * launches of your application.
333 *
334 * This is done asynchronously and may not be immediately reflected in monitoredRegions.
335 *
336 * @param {Region} region An instance of {Region} which will be monitored
337 * by the operating system.
338 *
339 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
340 * native layer acknowledged the dispatch of the request to stop monitoring.
341 */
342 static stopMonitoringForRegion(region: BeaconRegion): Promise<void>;
343 /**
344 * Request state the for specified region. When result is ready
345 * didDetermineStateForRegion is triggered. This can be any region,
346 * also those which is not currently monitored.
347 *
348 * This is done asynchronously and may not be immediately reflected in monitoredRegions.
349 *
350 * @param {Region} region An instance of {Region} which will be monitored
351 * by the operating system.
352 *
353 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
354 * native layer acknowledged the dispatch of the request to stop monitoring.
355 */
356 static requestStateForRegion(region: Region): Promise<void>;
357 /**
358 * Start ranging the specified beacon region.
359 *
360 * If a region of the same type with the same identifier is already being
361 * monitored for this application, it will be removed from monitoring.
362 *
363 * This is done asynchronously and may not be immediately reflected in rangedRegions.
364 *
365 * @param {Region} region An instance of {BeaconRegion} which will be monitored
366 * by the operating system.
367 *
368 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
369 * native layer acknowledged the dispatch of the monitoring request.
370 */
371 static startRangingBeaconsInRegion(region: BeaconRegion): Promise<void>;
372 /**
373 * Stop ranging the specified region. It is valid to call
374 * stopMonitoringForRegion: for a region that was registered for ranging
375 * with a different location manager object, during this or previous
376 * launches of your application.
377 *
378 * This is done asynchronously and may not be immediately reflected in rangedRegions.
379 *
380 * @param {Region} region An instance of {BeaconRegion} which will be monitored
381 * by the operating system.
382 *
383 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
384 * native layer acknowledged the dispatch of the request to stop monitoring.
385 */
386 static stopRangingBeaconsInRegion(region: BeaconRegion): Promise<void>;
387 /**
388 * Queries the native layer to determine the current authorization in effect.
389 *
390 * @returns {Promise<IBeaconPluginResult>} Returns a promise which is resolved with the
391 * requested authorization status.
392 */
393 static getAuthorizationStatus(): Promise<IBeaconPluginResult>;
394 /**
395 * For iOS 8 and above only. The permission model has changed by Apple in iOS 8, making it necessary for apps to
396 * explicitly request permissions via methods like these:
397 * <a href="https://developer.apple.com/library/prerelease/iOS/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instm/CLLocationManager/requestWhenInUseAuthorization">requestWhenInUseAuthorization</a>
398 * <a href="https://developer.apple.com/library/prerelease/iOS/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instm/CLLocationManager/requestAlwaysAuthorization">requestAlwaysAuthorization</a>
399 *
400 * If you are using this plugin on Android devices only, you will never have to use this, nor {@code requestAlwaysAuthorization}
401 * @returns {Promise<void>} Returns a promise that is resolved when the request dialog is shown.
402 */
403 static requestWhenInUseAuthorization(): Promise<void>;
404 /**
405 * See the documentation of {@code requestWhenInUseAuthorization} for further details.
406 *
407 * @returns {Promise<void>} Returns a promise which is resolved when the native layer
408 * shows the request dialog.
409 */
410 static requestAlwaysAuthorization(): Promise<void>;
411 /**
412 *
413 * @returns {Promise<Region[]>} Returns a promise which is resolved with an {Array}
414 * of {Region} instances that are being monitored by the native layer.
415 */
416 static getMonitoredRegions(): Promise<Region[]>;
417 /**
418 *
419 * @returns {Promise<Region[]>} Returns a promise which is resolved with an {Array}
420 * of {Region} instances that are being ranged by the native layer.
421 */
422 static getRangedRegions(): Promise<Region[]>;
423 /**
424 * Determines if ranging is available or not, according to the native layer.
425 * @returns {Promise<boolean>} Returns a promise which is resolved with a {Boolean}
426 * indicating whether ranging is available or not.
427 */
428 static isRangingAvailable(): Promise<boolean>;
429 /**
430 * Determines if region type is supported or not, according to the native layer.
431 *
432 * @param {Region} region An instance of {Region} which will be checked
433 * by the operating system.
434 *
435 * @returns {Promise<boolean>} Returns a promise which is resolved with a {Boolean}
436 * indicating whether the region type is supported or not.
437 */
438 static isMonitoringAvailableForClass(region: Region): Promise<boolean>;
439 /**
440 * Start advertising the specified region.
441 *
442 * If a region a different identifier is already being advertised for
443 * this application, it will be replaced with the new identifier.
444 *
445 * This call will accept a valid beacon even when no BlueTooth is available,
446 * and will start when BlueTooth is powered on. See {IBeaconDelegate.}
447 *
448 * @param {Region} region An instance of {Region} which will be advertised
449 * by the operating system.
450 * @param {Integer} measuredPower: Optional parameter, if left empty, the device will
451 * use it's own default value.
452 *
453 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
454 * native layer acknowledged the dispatch of the advertising request.
455 */
456 static startAdvertising(region: Region, measuredPower: number): Promise<void>;
457 /**
458 * Stop advertising as a beacon.
459 *
460 * This is done asynchronously and may not be immediately reflected in isAdvertising.
461 *
462 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
463 * native layer acknowledged the dispatch of the request to stop advertising.
464 */
465 static stopAdvertising(region: Region): Promise<void>;
466 /**
467 * Determines if advertising is available or not, according to the native layer.
468 * @returns {Promise<void>} Returns a promise which is resolved with a {Boolean}
469 * indicating whether advertising is available or not.
470 */
471 static isAdvertisingAvailable(): Promise<boolean>;
472 /**
473 * Determines if advertising is currently active, according to the native layer.
474 * @returns {Promise<void>} Returns a promise which is resolved with a {Boolean}
475 * indicating whether advertising is active.
476 */
477 static isAdvertising(): Promise<boolean>;
478 /**
479 * Disables debug logging in the native layer. Use this method if you want
480 * to prevent this plugin from writing to the device logs.
481 *
482 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
483 * native layer has set the logging level accordingly.
484 */
485 static disableDebugLogs(): Promise<void>;
486 /**
487 * Enables the posting of debug notifications in the native layer. Use this method if you want
488 * to allow the plugin the posting local notifications.
489 * This can be very helpful when debugging how to apps behave when launched into the background.
490 *
491 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
492 * native layer has set the flag to enabled.
493 */
494 static enableDebugNotifications(): Promise<void>;
495 /**
496 * Disables the posting of debug notifications in the native layer. Use this method if you want
497 * to prevent the plugin from posting local notifications.
498 *
499 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
500 * native layer has set the flag to disabled.
501 */
502 static disableDebugNotifications(): Promise<void>;
503 /**
504 * Enables debug logging in the native layer. Use this method if you want
505 * a debug the inner workings of this plugin.
506 *
507 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
508 * native layer has set the logging level accordingly.
509 */
510 static enableDebugLogs(): Promise<void>;
511 /**
512 * Appends the provided [message] to the device logs.
513 * Note: If debug logging is turned off, this won't do anything.
514 *
515 * @param {String} message The message to append to the device logs.
516 *
517 * @returns {Promise<void>} Returns a promise which is resolved with the log
518 * message received by the native layer for appending. The returned message
519 * is expected to be equivalent to the one provided in the original call.
520 */
521 static appendToDeviceLog(message: string): Promise<void>;
522}