forked from transistorsoft/react-native-background-fetch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
181 lines (172 loc) · 7.87 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
declare module "react-native-background-fetch" {
interface AbstractConfig {
/**
* [Android only] Set false to continue background-fetch events after user terminates the app. Default to true.
*/
stopOnTerminate?:boolean;
/**
* [Android only] Set true to initiate background-fetch events when the device is rebooted. Defaults to false.
*/
startOnBoot?:boolean;
/**
* [Android only] Set true to enable Headless mechanism for handling fetch events after app termination.
*/
enableHeadless?:boolean;
/**
* [Android only]
*/
forceAlarmManager?:boolean;
/**
* [Android only] Set detailed description of the kind of network your job requires.
*
* If your job doesn't need a network connection, you don't need to use this option, as the default is [[BackgroundFetch.NEWORK_TYPE_NONE]].
*
* Calling this method defines network as a strict requirement for your job. If the network requested is not available your job will never run.
*/
requiredNetworkType?:NetworkType;
/**
* [Android only] Specify that to run this job, the device's battery level must not be low.
*
* This defaults to false. If true, the job will only run when the battery level is not low, which is generally the point where the user is given a "low battery" warning.
*/
requiresBatteryNotLow?:boolean;
/**
* [Android only] Specify that to run this job, the device's available storage must not be low.
*
* This defaults to false. If true, the job will only run when the device is not in a low storage state, which is generally the point where the user is given a "low storage" warning.
*/
requiresStorageNotLow?:boolean;
/**
* [Android only] Specify that to run this job, the device must be charging (or be a non-battery-powered device connected to permanent power, such as Android TV devices). This defaults to false.
*/
requiresCharging?:boolean;
/**
* [Android only] When set true, ensure that this job will not run if the device is in active use.
*
* The default state is false: that is, the for the job to be runnable even when someone is interacting with the device.
*
* This state is a loose definition provided by the system. In general, it means that the device is not currently being used interactively, and has not been in use for some time. As such, it is a good time to perform resource heavy jobs. Bear in mind that battery usage will still be attributed to your application, and surfaced to the user in battery stats.
*/
requiresDeviceIdle?:boolean;
}
interface TaskConfig extends AbstractConfig {
/**
* The name of the task. This will be used with [[BackgroundFetch.finish]] to signal task-completion.
*/
taskId:string;
/**
* The minimum interval in milliseconds to execute this task.
*/
delay:number;
/**
* Whether this task will continue executing or just a "one-shot".
*/
periodic?:boolean;
}
interface BackgroundFetchConfig extends AbstractConfig {
/**
* The minimum interval in minutes to execute background fetch events. Defaults to 15 minutes. Minimum is 15 minutes.
*/
minimumFetchInterval?:number;
}
/**
* | BackgroundFetchStatus | Description |
* |------------------------------------|-------------------------------------------------|
* | BackgroundFetch.STATUS_RESTRICTED | Background fetch updates are unavailable and the user cannot enable them again. For example, this status can occur when parental controls are in effect for the current user. |
* | BackgroundFetch.STATUS_DENIED | The user explicitly disabled background behavior for this app or for the whole system. |
* | BackgroundFetch.STATUS_AVAILABLE | Background fetch is available and enabled. |
*/
type BackgroundFetchStatus = 0 | 1 | 2;
/**
* | NetworkType | Description |
* |---------------------------------------|---------------------------------------------------------------|
* | BackgroundFetch.NETWORK_TYPE_NONE | This job doesn't care about network constraints, either any or none. |
* | BackgroundFetch.NETWORK_TYPE_ANY | This job requires network connectivity. |
* | BackgroundFetch.NETWORK_TYPE_CELLULAR | This job requires network connectivity that is a cellular network. |
* | BackgroundFetch.NETWORK_TYPE_UNMETERED | This job requires network connectivity that is unmetered. |
* | BackgroundFetch.NETWORK_TYPE_NOT_ROAMING | This job requires network connectivity that is not roaming. |
*/
type NetworkType = 0 | 1 | 2 | 3 | 4;
export interface HeadlessEvent {
/**
* The name of the task. This will be used with [[BackgroundFetch.finish]] to signal task-completion.
*/
taskId: string;
/**
* Whether this event is a timeout event or not. If true stop all processing and call [[BackgroundFetch.finish]] immediately.
*/
timeout: boolean;
}
/**
* BackgroundFetch is a module to receive periodic callbacks (min every 15 min) while your app is running in the background or terminated.
*/
export default class BackgroundFetch {
/**
* Background fetch updates are unavailable and the user cannot enable them again. For example, this status can occur when parental controls are in effect for the current user.
*/
static STATUS_RESTRICTED: BackgroundFetchStatus;
/**
* The user explicitly disabled background behavior for this app or for the whole system.
*/
static STATUS_DENIED: BackgroundFetchStatus;
/**
* Background fetch is available and enabled.
*/
static STATUS_AVAILABLE: BackgroundFetchStatus;
/**
* This job doesn't care about network constraints, either any or none.
*/
static NETWORK_TYPE_NONE: NetworkType;
/**
* This job requires network connectivity.
*/
static NETWORK_TYPE_ANY: NetworkType;
/**
* This job requires network connectivity that is a cellular network.
*/
static NETWORK_TYPE_CELLULAR: NetworkType;
/**
* This job requires network connectivity that is unmetered.
*/
static NETWORK_TYPE_UNMETERED: NetworkType;
/**
* This job requires network connectivity that is not roaming.
*/
static NETWORK_TYPE_NOT_ROAMING: NetworkType;
/**
* Initial configuration of BackgroundFetch, including config-options and Fetch-callback. The [[start]] method will automatically be executed.
*/
static configure(config:BackgroundFetchConfig, onEvent:(taskId:string) => void, onTimeout?:(taskId:string) => void):Promise<BackgroundFetchStatus>;
/**
* Add an extra fetch event listener in addition to the one initially provided to [[configure]].
* @event
*/
static scheduleTask(config:TaskConfig):Promise<boolean>;
/**
* Start subscribing to fetch events.
*/
static start():Promise<BackgroundFetchStatus>;
/**
* Stop subscribing to fetch events.
*/
static stop(taskId?:string):Promise<boolean>;
/**
* You must execute [[finish]] within your fetch-callback to signal completion of your task.
*/
static finish(taskId?:string):void;
/**
* Query the BackgroundFetch API status
*
* | BackgroundFetchStatus | Description |
* |------------------------------------|-------------------------------------------------|
* | BackgroundFetch.STATUS_RESTRICTED | Background fetch updates are unavailable and the user cannot enable them again. For example, this status can occur when parental controls are in effect for the current user. |
* | BackgroundFetch.STATUS_DENIED | The user explicitly disabled background behavior for this app or for the whole system. |
* | BackgroundFetch.STATUS_AVAILABLE | Background fetch is available and enabled. |
*/
static status(callback?:(status:BackgroundFetchStatus) => void):Promise<BackgroundFetchStatus>;
/**
* [Android only] Register a function to execute when the app is terminated. Requires stopOnTerminate: false.
*/
static registerHeadlessTask(task:(event:HeadlessEvent) => void):void;
}
}