You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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`**:
39
39
40
40
**`app.ts`**
41
41
```diff
42
-
import application = require("application");
42
+
import * as app from 'application';
43
43
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];
47
49
+ // BackgroundFetch delegate method
48
-
+ public applicationPerformFetchWithCompletionHandler(application: UIApplication, completionHandler:any) {
**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'.
56
65
```
57
66
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
+
```
58
86
59
87
## Demo app
60
88
The plugin hosts its own demo app in the `/demo` folder. Install it like this:
0 commit comments