1 | ;
|
2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7 | };
|
8 | var plugin_1 = require('./plugin');
|
9 | var Observable_1 = require('rxjs/Observable');
|
10 | /**
|
11 | * @name Geofence
|
12 | * @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.
|
13 | * Geofences persist after device reboot. Geofences will be monitored even when the app is not running.
|
14 | * @usage
|
15 | * ```
|
16 | * import { Geofence } from 'ionic-native';
|
17 | * import { Platform } from 'ionic-angular'
|
18 | * ...
|
19 | *
|
20 | * constructor(private platform: Platform) {
|
21 | * this.platform.ready().then(() => {
|
22 | // initialize the plugin
|
23 | * Geofence.initialize().then(
|
24 | * // resolved promise does not return a value
|
25 | * () => console.log('Geofence Plugin Ready'),
|
26 | * (err) => console.log(err)
|
27 | * )
|
28 | * })
|
29 | * }
|
30 | *
|
31 | * private addGeofence() {
|
32 | * //options describing geofence
|
33 | * let fence = {
|
34 | * id: "69ca1b88-6fbe-4e80-a4d4-ff4d3748acdb", //any unique ID
|
35 | * latitude: 37.285951, //center of geofence radius
|
36 | * longitude: -121.936650,
|
37 | * radius: 100, //radius to edge of geofence
|
38 | * transitionType: 3, //see 'Transition Types' below
|
39 | * notification: { //notification settings
|
40 | * id: 1, //any unique ID
|
41 | * title: "You crossed a fence", //notification title
|
42 | * text: "You just arrived to Gliwice city center.", //notification body
|
43 | * openAppOnClick: true //open app when notification is tapped
|
44 | * }
|
45 | * }
|
46 | *
|
47 | * Geofence.addOrUpdate(fence).then(
|
48 | * () => console.log('Geofence added'),
|
49 | * (err) => console.log('Geofence failed to add')
|
50 | * );
|
51 | * }
|
52 | *
|
53 | * ```
|
54 | * ### Transition Types ###
|
55 | * Transition type specifies whether the geofence should trigger when the user enters and/or leaves the geofence.
|
56 | *
|
57 | * #### Supported values ####
|
58 | * - 1: Enter
|
59 | * - 2: Leave
|
60 | * - 3: Both
|
61 | *
|
62 | * ### Defining a Geofence ###
|
63 | * Geofences are defined by an object that is passed to `addOrUpdate()`. Object properties are:
|
64 | * - id: Any unique ID for the geofence. This ID is used to remove and update a geofence
|
65 | * - latitude: Latitude coordinate of the center of the geofence radius
|
66 | * - longitude: Latitude coordinate of the center of the geofence radius
|
67 | * - radius: Radius from the center to the edge of the geofence
|
68 | * - transitionType: Type of geofence transition to monitor for. See 'Transition Types' above
|
69 | * - notification: Object. Options for defining the notification sent when a geofence is crossed
|
70 | * - id: Any unique ID
|
71 | * - title: Notification title
|
72 | * - text: Notification body
|
73 | * - openAppOnClick: Boolean. Whether to open the app when the notification is tapped by the user
|
74 | *
|
75 | * ### Troubleshooting ###
|
76 | * #### I get compile errors when I run `ionic build ios` or `ionic run ios`. ####
|
77 | * This could be caused by the Cordova project directory in `/platforms/ios` not being named correctly.
|
78 | * Try running `ionic platform rm <platform>` then run `ionic platform add <platform>` to recreate the
|
79 | * platform directories.
|
80 | */
|
81 | var Geofence = (function () {
|
82 | function Geofence() {
|
83 | }
|
84 | /**
|
85 | * Initializes the plugin. User will be prompted to allow the app to use location and notifications.
|
86 | *
|
87 | * @returns {Promise<void>}
|
88 | */
|
89 | Geofence.initialize = function () { return; };
|
90 | ;
|
91 | /**
|
92 | * Adds a new geofence or array of geofences. For geofence object, see above.
|
93 | *
|
94 | * @returns {Promise<void>}
|
95 | */
|
96 | Geofence.addOrUpdate = function (geofences) { return; };
|
97 | ;
|
98 | /**
|
99 | * Removes a geofence or array of geofences. `geofenceID` corresponds to one or more IDs specified when the
|
100 | * geofence was created.
|
101 | *
|
102 | * @returns {Promise<void>}
|
103 | */
|
104 | Geofence.remove = function (geofenceId) { return; };
|
105 | ;
|
106 | /**
|
107 | * Removes all geofences.
|
108 | *
|
109 | * @returns {Promise<void>}
|
110 | */
|
111 | Geofence.removeAll = function () { return; };
|
112 | ;
|
113 | /**
|
114 | * Returns an array of geofences currently being monitored.
|
115 | *
|
116 | * @returns {Promise<Array<string>>}
|
117 | */
|
118 | Geofence.getWatched = function () { return; };
|
119 | ;
|
120 | /**
|
121 | * Called when a geofence is crossed in the direction specified by `TransitType`.
|
122 | *
|
123 | * @returns {Observable<any>}
|
124 | */
|
125 | Geofence.onTransitionReceived = function () {
|
126 | return new Observable_1.Observable(function (observer) {
|
127 | window && window.geofence && (window.geofence.onTransitionReceived = observer.next.bind(observer));
|
128 | return function () { return window.geofence.onTransitionReceived = function () { }; };
|
129 | });
|
130 | };
|
131 | /**
|
132 | * Called when the user clicks a geofence notification. iOS and Android only.
|
133 | *
|
134 | * @returns {Observable<any>}
|
135 | */
|
136 | Geofence.onNotificationClicked = function () {
|
137 | return new Observable_1.Observable(function (observer) {
|
138 | window && window.geofence && (window.geofence.onNotificationClicked = observer.next.bind(observer));
|
139 | return function () { return window.geofence.onNotificationClicked = function () { }; };
|
140 | });
|
141 | };
|
142 | Geofence.TransitionType = {
|
143 | ENTER: 1,
|
144 | EXIT: 2,
|
145 | BOTH: 3
|
146 | };
|
147 | __decorate([
|
148 | plugin_1.Cordova()
|
149 | ], Geofence, "initialize", null);
|
150 | __decorate([
|
151 | plugin_1.Cordova()
|
152 | ], Geofence, "addOrUpdate", null);
|
153 | __decorate([
|
154 | plugin_1.Cordova()
|
155 | ], Geofence, "remove", null);
|
156 | __decorate([
|
157 | plugin_1.Cordova()
|
158 | ], Geofence, "removeAll", null);
|
159 | __decorate([
|
160 | plugin_1.Cordova()
|
161 | ], Geofence, "getWatched", null);
|
162 | Geofence = __decorate([
|
163 | plugin_1.Plugin({
|
164 | pluginName: 'Geofence',
|
165 | plugin: 'cordova-plugin-geofence',
|
166 | pluginRef: 'geofence',
|
167 | repo: 'https://github.com/cowbell/cordova-plugin-geofence/',
|
168 | platforms: ['Android', 'iOS', 'Windows Phone 8', 'Windows Phone']
|
169 | })
|
170 | ], Geofence);
|
171 | return Geofence;
|
172 | }());
|
173 | exports.Geofence = Geofence;
|
174 | //# sourceMappingURL=geofence.js.map |
\ | No newline at end of file |