1 Star 0 Fork 0

badou119@126.com/react-native-background-fetch

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
index.js 2.35 KB
一键复制 编辑 原始数据 按行查看 历史
Chris Scott 提交于 2018-10-29 23:43 +08:00 . Add Typescript definitions
'use strict'
import {
NativeModules,
NativeEventEmitter,
AppRegistry
} from "react-native";
const RNBackgroundFetch = NativeModules.RNBackgroundFetch;
const EventEmitter = new NativeEventEmitter(RNBackgroundFetch);
const EVENT_FETCH = "fetch";
const TAG = "RNBackgroundFetch";
const EVENTS = ["fetch"];
const STATUS_RESTRICTED = 0;
const STATUS_DENIED = 1;
const STATUS_AVAILABLE = 2;
const FETCH_RESULT_NEW_DATA = 0;
const FETCH_RESULT_NO_DATA = 1;
const FETCH_RESULT_FAILED = 2;
export default class BackgroundFetch {
static get STATUS_RESTRICTED() { return STATUS_RESTRICTED; }
static get STATUS_DENIED() { return STATUS_DENIED; }
static get STATUS_AVAILABLE() { return STATUS_AVAILABLE; }
static get FETCH_RESULT_NEW_DATA() { return FETCH_RESULT_NEW_DATA; }
static get FETCH_RESULT_NO_DATA() { return FETCH_RESULT_NO_DATA; }
static get FETCH_RESULT_FAILED() { return FETCH_RESULT_FAILED; }
static configure(config, callback, failure) {
if (typeof(callback) !== 'function') {
throw "RNBackgroundFetch requires a fetch callback at 2nd argument";
}
EventEmitter.removeAllListeners('fetch');
config = config || {};
failure = failure || function() {};
RNBackgroundFetch.configure(config, failure);
return this.addListener(EVENT_FETCH, callback);
}
/**
* Register HeadlessTask
*/
static registerHeadlessTask(task) {
AppRegistry.registerHeadlessTask("BackgroundFetch", () => task);
}
static onFetch(callback) {
this.addListener('fetch', callback);
}
static on(event, callback) {
return this.addListener(event, callback);
}
static addListener(event, callback) {
if (EVENTS.indexOf(event) < 0) {
throw "RNBackgroundFetch: Unknown event '" + event + '"';
}
return EventEmitter.addListener(event, callback);
}
static start(success, failure) {
success = success || function() {};
failure = failure || function() {};
RNBackgroundFetch.start(success, failure);
}
static stop() {
RNBackgroundFetch.stop();
}
static finish(result) {
const fetchResult = result ? result : FETCH_RESULT_NEW_DATA;
RNBackgroundFetch.finish(fetchResult);
}
static status(callback) {
if (typeof(callback) !== 'function') {
throw "RNBackgroundFetch#status requires a callback as 1st argument";
}
RNBackgroundFetch.status(callback);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/badou119/react-native-background-fetch.git
git@gitee.com:badou119/react-native-background-fetch.git
badou119
react-native-background-fetch
react-native-background-fetch
master

搜索帮助