如何在React Native中运行后台任务? [英] How can I run background tasks in React Native?

查看:1896
本文介绍了如何在React Native中运行后台任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在React Native中构建了一个小iOS应用来进行位置跟踪,发送lat /定期到用户选择的服务器。但是,这只适用于应用程序位于前台的情况。当用户在其他应用程序中时,如何在后台运行此任务?

I've built a little iOS app in React Native that does location tracking, sending the lat/lng regularly to a server of the user's choosing. However this only works when the app is in the foreground. How can I run this task in the background when the user is in other apps?

推荐答案

目前,不幸的是,没有支持任何类型的后台任务。您指的功能将是后台计时器。这样的计时器是这个产品的痛苦(功能请求) ,您可以对其进行投票,以显示对此功能的需求增加。

Currently, there is, unfortunately, no support for background tasks of any kind. The feature you are referring to would be a background timer. Such a timer is this product pain (a feature request) for react native, you may upvote it to show an increased demand for this feature.

编辑12/2016:仍然没有真正的选择。自RN 0.33起,你有 Headless JS API,但是它只适用于Android。如果它在前台运行,你的应用程序也会崩溃所以你必须小心使用它。感谢@Feng指出这一点。

EDIT 12/2016: There is still no real option. You have the Headless JS API since RN 0.33, but it is only for android. Also your App will crash if this runs in the foreground so you have to be careful about using it. Thanks to @Feng for pointing that out.

这篇关于如何在React Native中运行后台任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆