UNPKG

2.14 kBJavaScriptView Raw
1import * as TaskManager from 'expo-task-manager';
2import { UnavailabilityError } from '@unimodules/core';
3import { Platform, NativeModulesProxy } from '@unimodules/core';
4const { ExpoBackgroundFetch } = NativeModulesProxy;
5var 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 = {}));
11var 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 = {}));
17export async function getStatusAsync() {
18 if (Platform.OS !== 'ios') {
19 return BackgroundFetchStatus.Available;
20 }
21 return ExpoBackgroundFetch.getStatusAsync();
22}
23export async function setMinimumIntervalAsync(minimumInterval) {
24 if (Platform.OS !== 'ios') {
25 return;
26 }
27 await ExpoBackgroundFetch.setMinimumIntervalAsync(minimumInterval);
28}
29export 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}
38export async function unregisterTaskAsync(taskName) {
39 if (!ExpoBackgroundFetch.unregisterTaskAsync) {
40 throw new UnavailabilityError('BackgroundFetch', 'unregisterTaskAsync');
41 }
42 await ExpoBackgroundFetch.unregisterTaskAsync(taskName);
43}
44export { BackgroundFetchResult as Result, BackgroundFetchStatus as Status, };
45//# sourceMappingURL=BackgroundFetch.js.map
\No newline at end of file