搜索插件、代码仓与 APP 分类

插件详情v1.7.0

background_fetch

在 iOS 和 Android 上均支持后台的周期性回调。包含 Android 的无头实现。

AndroidiOS
近 30 天下载
11.5万
喜欢数
1260
Pub 分数
155

安装插件

flutter pub add background_fetch

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 插件,可在 Android 和 iOS 上实现周期性后台执行,使应用程序即使在关闭状态下也能执行同步数据或获取更新等任务。它支持 Android 的 Headless JS 模式以实现可靠的后台处理,并提供跨平台一致的回调。专为需要可靠后台活动但不依赖平台特定解决方案的开发者设计。

适合场景

  • 背景数据同步
  • 周期性任务执行
  • 推送通知处理
  • 应用状态维护
  • 位置跟踪
  • 离线数据更新

主要特点

  • 跨平台支持(Android 和 iOS)
  • Android 无头实现
  • 可配置的背景间隔
  • 持久的后台执行
  • 事件驱动的回调系统
  • 低电量和电源优化

适合对象

  • 需要定期后台更新的应用
  • 数据密集型应用
  • 离线优先的移动应用
  • 跟踪或监控服务
  • 后台任务自动化

使用建议

  • Android 需要后台权限
  • 可能影响电池续航
  • iOS 后台执行受系统策略限制
  • 需要正确配置以支持无头模式
  • 后台获取可能被操作系统限制
  • 需要在真实设备上进行测试以确保可靠性

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Background Fetch for Flutter

background_fetch · pub package

By Transistor Software, creators of Flutter Background Geolocation


Background Fetch is a very simple plugin which attempts to awaken an app in the background about every 15 minutes, providing a short period 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 — you will never receive an event faster than 15 minutes. The operating-system will automatically throttle the rate the background-fetch events occur based upon usage patterns. Eg: if user hasn't turned on their phone for a long period of time, fetch events will occur less frequently or if an iOS user disables background refresh they may not happen at all.

:new: Background Fetch now provides a scheduleTask method for scheduling arbitrary "one-shot" or periodic tasks.

iOS
  • There is no way to increase the rate which a fetch-event occurs and this plugin sets the rate to the most frequent possible — you will never receive an event faster than 15 minutes. The operating-system will automatically throttle the rate the background-fetch events occur based upon usage patterns. Eg: if user hasn't turned on their phone for a long period of time, fetch events will occur less frequently.
  • scheduleTask seems only to fire when the device is plugged into power.
  • :warning: When your app is terminated, iOS no longer fires events — There is no such thing as stopOnTerminate: false for iOS.
  • iOS can take days before Apple's machine-learning algorithm settles in and begins regularly firing events. Do not sit staring at your logs waiting for an event to fire. If your simulated events work, that's all you need to know that everything is correctly configured.
  • If the user doesn't open your iOS app for long periods of time, iOS will stop firing events.
Android
  • The Android plugin provides a Headless implementation allowing you to continue handling events even after app-termination.

Contents

Licence

The MIT License

Copyright (c) 2018 Chris Scott, Transistor Software <chris@transistorsoft.com> https://www.transistorsoft.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

所属分类

源码仓库

使用此插件的项目