UNPKG

4.05 kBTypeScriptView Raw
1export interface BackgroundFetchConfig {
2 /**
3 * Set true to cease background-fetch from operating after user "closes" the app. Defaults to true.
4 */
5 stopOnTerminate?: boolean;
6}
7/**
8 * @name BackgroundFetch
9 * @description
10 * iOS Background Fetch Implementation. See: https://developer.apple.com/reference/uikit/uiapplication#1657399
11 * iOS Background Fetch is basically an API which wakes up your app about every 15 minutes (during the user's prime-time hours) and provides your app exactly 30s of background running-time. This plugin will execute your provided callbackFn whenever a background-fetch event occurs. There is no way to increase the rate which a fetch-event occurs and this plugin sets the rate to the most frequent possible value of UIApplicationBackgroundFetchIntervalMinimum -- iOS determines the rate automatically based upon device usage and time-of-day (ie: fetch-rate is about ~15min during prime-time hours; less frequently when the user is presumed to be sleeping, at 3am for example).
12 * For more detail, please see https://github.com/transistorsoft/cordova-plugin-background-fetch
13 *
14 * @usage
15 *
16 * ```typescript
17 * import { BackgroundFetch } from 'ionic-native';
18 *
19 *
20 * // When device is ready :
21 * platform.ready().then(() => {
22 *
23 * let config = {
24 * stopOnTerminate: false, // Set true to cease background-fetch from operating after user "closes" the app. Defaults to true.
25 * };
26 *
27 * BackgroundFetch.configure(() => {
28 console.log('[js] BackgroundFetch initiated');
29
30 // perform some ajax request to server here
31
32 You MUST called #finish so that native-side can signal completion of the background-thread to the os.
33 BackgroundFetch.finish();
34
35 * }, (error) => {
36 * console.log('- BackgroundFetch failed', error);
37 * }, config);
38 *
39 * });
40 *
41 * // Start the background-fetch API. Your callbackFn provided to #configure will be executed each time a background-fetch event occurs. NOTE the #configure method automatically calls #start. You do not have to call this method after you #configure the plugin
42 * BackgroundFetch.start();
43 *
44 * // Stop the background-fetch API from firing fetch events. Your callbackFn provided to #configure will no longer be executed.
45 * BackgroundFetch.stop();
46 *
47 * ```
48 * @interfaces
49 * BackgroundFetchConfig
50 *
51 */
52export declare class BackgroundFetch {
53 /**
54 * Configures the plugin's fetch callbackFn
55 *
56 * @param {Function} callbackFn This callback will fire each time an iOS background-fetch event occurs (typically every 15 min).
57 * @param {Function} errorCallback The failureFn will be called if the device doesn't support background-fetch.
58 * @param {BackgroundFetchConfig} config Configuration for plugin
59 * @return Location object, which tries to mimic w3c Coordinates interface.
60 * See http://dev.w3.org/geo/api/spec-source.html#coordinates_interface
61 * Callback to be executed every time a geolocation is recorded in the background.
62 */
63 static configure(callbackFn: Function, errorCallback: Function, config: BackgroundFetchConfig): any;
64 /**
65 * Start the background-fetch API.
66 * Your callbackFn provided to #configure will be executed each time a background-fetch event occurs. NOTE the #configure method automatically calls #start. You do not have to call this method after you #configure the plugin
67 * @returns {Promise<any>}
68 */
69 static start(): Promise<any>;
70 /**
71 * Stop the background-fetch API from firing fetch events. Your callbackFn provided to #configure will no longer be executed.
72 * @returns {Promise<any>}
73 */
74 static stop(): Promise<any>;
75 /**
76 * You MUST call this method in your fetch callbackFn provided to #configure in order to signal to iOS that your fetch action is complete. iOS provides only 30s of background-time for a fetch-event -- if you exceed this 30s, iOS will kill your app.
77 */
78 static finish(): void;
79}