UNPKG

4.75 kBTypeScriptView Raw
1import { Observable } from 'rxjs/Observable';
2/**
3 * @name Geofence
4 * @description Monitors circular geofences around latitude/longitude coordinates, and sends a notification to the user when the boundary of a geofence is crossed. Notifications can be sent when the user enters and/or exits a geofence.
5 * Geofences persist after device reboot. Geofences will be monitored even when the app is not running.
6 * @usage
7 * ```
8 * import { Geofence } from 'ionic-native';
9 * import { Platform } from 'ionic-angular'
10 * ...
11 *
12 * constructor(private platform: Platform) {
13 * this.platform.ready().then(() => {
14 // initialize the plugin
15 * Geofence.initialize().then(
16 * // resolved promise does not return a value
17 * () => console.log('Geofence Plugin Ready'),
18 * (err) => console.log(err)
19 * )
20 * })
21 * }
22 *
23 * private addGeofence() {
24 * //options describing geofence
25 * let fence = {
26 * id: "69ca1b88-6fbe-4e80-a4d4-ff4d3748acdb", //any unique ID
27 * latitude: 37.285951, //center of geofence radius
28 * longitude: -121.936650,
29 * radius: 100, //radius to edge of geofence
30 * transitionType: 3, //see 'Transition Types' below
31 * notification: { //notification settings
32 * id: 1, //any unique ID
33 * title: "You crossed a fence", //notification title
34 * text: "You just arrived to Gliwice city center.", //notification body
35 * openAppOnClick: true //open app when notification is tapped
36 * }
37 * }
38 *
39 * Geofence.addOrUpdate(fence).then(
40 * () => console.log('Geofence added'),
41 * (err) => console.log('Geofence failed to add')
42 * );
43 * }
44 *
45 * ```
46 * ### Transition Types ###
47 * Transition type specifies whether the geofence should trigger when the user enters and/or leaves the geofence.
48 *
49 * #### Supported values ####
50 * - 1: Enter
51 * - 2: Leave
52 * - 3: Both
53 *
54 * ### Defining a Geofence ###
55 * Geofences are defined by an object that is passed to `addOrUpdate()`. Object properties are:
56 * - id: Any unique ID for the geofence. This ID is used to remove and update a geofence
57 * - latitude: Latitude coordinate of the center of the geofence radius
58 * - longitude: Latitude coordinate of the center of the geofence radius
59 * - radius: Radius from the center to the edge of the geofence
60 * - transitionType: Type of geofence transition to monitor for. See 'Transition Types' above
61 * - notification: Object. Options for defining the notification sent when a geofence is crossed
62 * - id: Any unique ID
63 * - title: Notification title
64 * - text: Notification body
65 * - openAppOnClick: Boolean. Whether to open the app when the notification is tapped by the user
66 *
67 * ### Troubleshooting ###
68 * #### I get compile errors when I run `ionic build ios` or `ionic run ios`. ####
69 * This could be caused by the Cordova project directory in `/platforms/ios` not being named correctly.
70 * Try running `ionic platform rm <platform>` then run `ionic platform add <platform>` to recreate the
71 * platform directories.
72 */
73export declare class Geofence {
74 static TransitionType: {
75 ENTER: number;
76 EXIT: number;
77 BOTH: number;
78 };
79 static onTrasitionReceived: Function;
80 /**
81 * Initializes the plugin. User will be prompted to allow the app to use location and notifications.
82 *
83 * @returns {Promise<void>}
84 */
85 static initialize(): Promise<void>;
86 /**
87 * Adds a new geofence or array of geofences. For geofence object, see above.
88 *
89 * @returns {Promise<void>}
90 */
91 static addOrUpdate(geofences: Object | Array<Object>): Promise<void>;
92 /**
93 * Removes a geofence or array of geofences. `geofenceID` corresponds to one or more IDs specified when the
94 * geofence was created.
95 *
96 * @returns {Promise<void>}
97 */
98 static remove(geofenceId: string | Array<string>): Promise<void>;
99 /**
100 * Removes all geofences.
101 *
102 * @returns {Promise<void>}
103 */
104 static removeAll(): Promise<void>;
105 /**
106 * Returns an array of geofences currently being monitored.
107 *
108 * @returns {Promise<Array<string>>}
109 */
110 static getWatched(): Promise<string>;
111 /**
112 * Called when a geofence is crossed in the direction specified by `TransitType`.
113 *
114 * @returns {Observable<any>}
115 */
116 static onTransitionReceived(): Observable<any>;
117 /**
118 * Called when the user clicks a geofence notification. iOS and Android only.
119 *
120 * @returns {Observable<any>}
121 */
122 static onNotificationClicked(): Observable<any>;
123}