1 | import * as TaskManager from 'expo-task-manager';
|
2 | import { UnavailabilityError } from '@unimodules/core';
|
3 | import { Platform, NativeModulesProxy } from '@unimodules/core';
|
4 | const { ExpoBackgroundFetch } = NativeModulesProxy;
|
5 | var BackgroundFetchResult;
|
6 | (function (BackgroundFetchResult) {
|
7 | BackgroundFetchResult[BackgroundFetchResult["NoData"] = 1] = "NoData";
|
8 | BackgroundFetchResult[BackgroundFetchResult["NewData"] = 2] = "NewData";
|
9 | BackgroundFetchResult[BackgroundFetchResult["Failed"] = 3] = "Failed";
|
10 | })(BackgroundFetchResult || (BackgroundFetchResult = {}));
|
11 | var BackgroundFetchStatus;
|
12 | (function (BackgroundFetchStatus) {
|
13 | BackgroundFetchStatus[BackgroundFetchStatus["Denied"] = 1] = "Denied";
|
14 | BackgroundFetchStatus[BackgroundFetchStatus["Restricted"] = 2] = "Restricted";
|
15 | BackgroundFetchStatus[BackgroundFetchStatus["Available"] = 3] = "Available";
|
16 | })(BackgroundFetchStatus || (BackgroundFetchStatus = {}));
|
17 | export async function getStatusAsync() {
|
18 | if (Platform.OS !== 'ios') {
|
19 | return BackgroundFetchStatus.Available;
|
20 | }
|
21 | return ExpoBackgroundFetch.getStatusAsync();
|
22 | }
|
23 | export async function setMinimumIntervalAsync(minimumInterval) {
|
24 | if (Platform.OS !== 'ios') {
|
25 | return;
|
26 | }
|
27 | await ExpoBackgroundFetch.setMinimumIntervalAsync(minimumInterval);
|
28 | }
|
29 | export async function registerTaskAsync(taskName, options = {}) {
|
30 | if (!ExpoBackgroundFetch.registerTaskAsync) {
|
31 | throw new UnavailabilityError('BackgroundFetch', 'registerTaskAsync');
|
32 | }
|
33 | if (!TaskManager.isTaskDefined(taskName)) {
|
34 | throw new Error(`Task '${taskName}' is not defined. You must define a task using TaskManager.defineTask before registering.`);
|
35 | }
|
36 | await ExpoBackgroundFetch.registerTaskAsync(taskName, options);
|
37 | }
|
38 | export async function unregisterTaskAsync(taskName) {
|
39 | if (!ExpoBackgroundFetch.unregisterTaskAsync) {
|
40 | throw new UnavailabilityError('BackgroundFetch', 'unregisterTaskAsync');
|
41 | }
|
42 | await ExpoBackgroundFetch.unregisterTaskAsync(taskName);
|
43 | }
|
44 | export { BackgroundFetchResult as Result, BackgroundFetchStatus as Status, };
|
45 |
|
\ | No newline at end of file |