Skip to content

Commit 324581c

Browse files
committed
Merge branch 'refactor-api'
2 parents 55778fb + dc190d9 commit 324581c

8 files changed

+53
-39
lines changed

README.md

+38-10
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,54 @@ $ tns plugin add /path/to/nativescript-background-geolocation-lt
3535

3636
## iOS Setup
3737

38-
Since iOS is more strict with apps running in the background, this plugin includes the dependency [nativescript-background-fetch](https://github.com/transistorsoft/nativescript-background-fetch) (also created by [Transistor Software](http://transistorsoft.com)). This plugin automatically awakens a suspended app in the background, providing *exactly* 30s of running-time. Actually implementing **`background-fetch`** in your application code is **optional** -- `background-geolocation` uses it automatically under-the-hood for its own purposes. However, you **must** perform the plugin's [setup process](https://github.com/transistorsoft/nativescript-background-fetch#setup) in your **`app.ts`**:
38+
Since iOS is more strict with apps running in the background, this plugin requires you install [nativescript-background-fetch](https://github.com/transistorsoft/nativescript-background-fetch) (also created by [Transistor Software](http://transistorsoft.com)). This plugin automatically awakens a suspended app in the background, providing *exactly* 30s of running-time. Actually implementing **`background-fetch`** in your application code is **optional** -- `background-geolocation` uses it automatically under-the-hood for its own purposes. However, you **must** perform the plugin's [setup process](https://github.com/transistorsoft/nativescript-background-fetch#setup) in your **`app.ts`**:
3939

4040
**`app.ts`**
4141
```diff
42-
import application = require("application");
42+
import * as app from 'application';
4343

44-
+ if (application.ios) {
45-
+ class MyDelegate extends UIResponder {
46-
+ public static ObjCProtocols = [UIApplicationDelegate];
44+
+import {BackgroundFetch} from "nativescript-background-fetch";
45+
46+
+if (app.ios) {
47+
+ class MyDelegate extends UIResponder implements UIApplicationDelegate {
48+
+ public static ObjCProtocols = [UIApplicationDelegate];
4749
+ // BackgroundFetch delegate method
48-
+ public applicationPerformFetchWithCompletionHandler(application: UIApplication, completionHandler:any) {
49-
+ TSBackgroundFetch.sharedInstance().performFetchWithCompletionHandler(completionHandler);
50+
+ public applicationPerformFetchWithCompletionHandler(application: any, completionHandler:any) {
51+
+ BackgroundFetch.performFetchWithCompletionHandler(completionHandler);
5052
+ }
5153
+ }
52-
+ application.ios.delegate = MyDelegate;
53-
+}
54+
+ app.ios.delegate = MyDelegate;
55+
+}
56+
57+
app.start({ moduleName: 'main-page' });
58+
```
5459

55-
application.start({ moduleName: "main-page" });
60+
**NOTE** If your build fails with the following errors:
61+
```
62+
app/app.ts(6,28): error TS2304: Cannot find name 'UIResponder'.
63+
app/app.ts(6,51): error TS2304: Cannot find name 'UIApplicationDelegate'.
64+
app/app.ts(7,36): error TS2304: Cannot find name 'UIApplicationDelegate'.
5665
```
5766

67+
This is because your app hasn't loaded the ios platform-declarations. You can either load those (if you know how ;)) or simply configure your `tsconfig.json` to ignore errors:
68+
69+
```diff
70+
{
71+
"compilerOptions": {
72+
"module": "commonjs",
73+
"target": "es5",
74+
"sourceMap": true,
75+
"experimentalDecorators": true,
76+
"emitDecoratorMetadata": true,
77+
"noEmitHelpers": true,
78+
+ "noEmitOnError": false
79+
},
80+
"exclude": [
81+
"node_modules",
82+
"platforms"
83+
]
84+
}
85+
```
5886

5987
## Demo app
6088
The plugin hosts its own demo app in the `/demo` folder. Install it like this:

background-geolocation.ios.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export declare class BackgroundGeolocation extends AbstractBackgroundGeolocation
5858
private static onActivityChange(activityName);
5959
private static onProviderChange(status);
6060
private static onSchedule(schedule);
61+
private static getAdapter();
6162
private static getLocationManager();
6263
private static getJsObjectFromNSDictionary(dictionary);
6364
private static getJsArrayFromNSArray(array);

background-geolocation.ios.ts

+3
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,9 @@ export class BackgroundGeolocation extends AbstractBackgroundGeolocation {
418418
}
419419
}
420420

421+
private static getAdapter() {
422+
423+
}
421424
private static getLocationManager() {
422425
if (!this.locationManager) {
423426
this.locationManager = TSLocationManager.sharedInstance();

demo/app/app.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as application from "application";
2+
import {BackgroundFetch} from "nativescript-background-fetch";
23

34
if(application.ios) {
45
GMSServices.provideAPIKey("AIzaSyAttgr9w-Wwu4TWkeMAPsYwaYvH2ibSPjQ");
@@ -14,18 +15,16 @@ TNSFontIcon.loadCss();
1415
application.resources['fonticon'] = fonticon;
1516

1617
if (application.ios) {
17-
class MyDelegate extends UIResponder {
18+
class MyDelegate extends UIResponder implements UIApplicationDelegate {
1819
public static ObjCProtocols = [UIApplicationDelegate];
1920

2021
public applicationPerformFetchWithCompletionHandler(application: UIApplication, completionHandler:any) {
2122
console.log('- AppDelegate Rx Fetch event');
22-
var fetchManager = TSBackgroundFetch.sharedInstance();
23-
fetchManager.performFetchWithCompletionHandler(completionHandler);
23+
BackgroundFetch.performFetchWithCompletionHandler(completionHandler);
2424
}
2525
}
2626
application.ios.delegate = MyDelegate;
2727
}
2828

29-
3029
application.start({ moduleName: "./pages/map/map-page" });
3130

demo/app/pages/map/map-view-model.ts

-19
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,9 @@ export class MapModel extends observable.Observable {
216216
public onMapReady(args) {
217217
this._mapView = args.object;
218218

219-
console.log('<<<<<<<<<<<<<< onMapReady >>>>>>>>>>>>>>>');
220-
221219
// If _state already exists, we're probably returning from a navigation-event. just ignore: we're already configured.
222220
if (this._state) { return };
223221

224-
console.log('<<<<<<<<<<<<<<<<< configure >>>>>>>>>>>>>>>>>');
225-
226222
// Listen to BackgroundGeolocation events
227223
BackgroundGeolocation.on('location', this.onLocation.bind(this), this.onLocationError.bind(this));
228224
BackgroundGeolocation.on('motionchange', this.onMotionChange.bind(this));
@@ -241,21 +237,6 @@ export class MapModel extends observable.Observable {
241237
this._enabled = state.enabled;
242238
this.notifyPropertyChange("isEnabled", state.enabled);
243239
this._isMoving = this._state.isMoving;
244-
245-
BackgroundGeolocation.getLog(function(log) {
246-
console.log('------------ log: ', log.length);
247-
248-
BackgroundGeolocation.destroyLog();
249-
BackgroundGeolocation.getCount(function(count) {
250-
console.log('-------- count: ', count);
251-
BackgroundGeolocation.destroyLocations();
252-
});
253-
254-
BackgroundGeolocation.getGeofences(function(geofences) {
255-
console.log('---------- geofences: ', geofences.length);
256-
BackgroundGeolocation.removeGeofences();
257-
});
258-
});
259240
}.bind(this));
260241
}
261242

demo/package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
},
99
"nativescript": {
1010
"id": "com.transistorsoft.backgroundgeolocation.nativescript",
11-
"tns-android": {
12-
"version": "2.1.0"
13-
},
1411
"tns-ios": {
1512
"version": "2.3.0"
13+
},
14+
"tns-android": {
15+
"version": "2.1.1"
1616
}
1717
},
1818
"dependencies": {
19+
"nativescript-background-fetch": "^1.0.2",
1920
"nativescript-background-geolocation-lt": "file:..",
2021
"nativescript-fonticon": "^1.1.0",
2122
"nativescript-google-maps-sdk": "^1.3.13",
@@ -31,4 +32,4 @@
3132
"nativescript-dev-typescript": "^0.3.2",
3233
"typescript": "^1.8.10"
3334
}
34-
}
35+
}

demo/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"target": "es5",
77
"experimentalDecorators": true,
88
"noEmitHelpers": true,
9+
"noEmitOnError": false,
910
"inlineSourceMap": true,
1011
"removeComments": false,
1112
"emitDecoratorMetadata": true
@@ -14,4 +15,4 @@
1415
"node_modules",
1516
"platforms"
1617
]
17-
}
18+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-background-geolocation-lt",
3-
"version": "1.2.2",
3+
"version": "1.2.3",
44
"description": "Sophisticated, battery-conscious, cross-platform background-geolocation with motion-detection and geofencing",
55
"main": "background-geolocation.js",
66
"typings": "background-geolocation.d.ts",

0 commit comments

Comments
 (0)