使用 Phonegap 在后台执行 Javascript

发布于 2024-12-06 20:50:24 字数 245 浏览 1 评论 0原文

我创建了一个应用程序,需要每“X”分钟触发一次 Javascript 事件。我正在使用手机间隙构建在 Android/iPhone/Blackberry 上部署,但我当然陷入困境,因为 Javascript 计时器不会在后台触发(当它们最小化应用程序时)。我想知道 Phonegap 是否有某种能力在应用程序在后台运行时触发 Javascript 事件。

或者有什么方法可以在这些主要手机上轻松实现这一点?我只需要使用手机中的地理位置信息发起 ajax 调用。

I've created an application that will need to fire Javascript events every "X" minutes. I'm using phone gap build to deploy on Android/iPhone/Blackberry, but I'm of course stuck, as the Javascript timer doesn't fire in the background (when they minimize the app). I was wondering if Phonegap had some sort of ability to fire Javascript events while the app is running in the background.

Or is there ANY way to accomplish this easily across these major phones? I just need to fire an ajax call with the geolocation info from the phones.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半城柳色半声笛 2024-12-13 20:50:24

是的,您可以做到,有一个 PhoneGap 插件可以完全满足您的需求:

PhoneGap + Background.js
https://github.com/jocull/phonegap-backgroundjs

小心配置你的 config.xml

Yes you can do it, there's a PhoneGap plugin that does exactly what you need:

PhoneGap + Background.js
https://github.com/jocull/phonegap-backgroundjs

Be careful configuring your config.xml

吾家有女初长成 2024-12-13 20:50:24

目前,phone gap 没有此选项。对于此类事情有很多请求,但我认为人们被 iOS 后台事件的 TOS 绊倒了。无论如何,电话间隙插件可以像@Chase提到的那样做到这一点,但这当然需要本机代码编写。

我假设您希望每 x 秒/分钟推送一次地理位置,以便您的服务器知道手机在任何时间点的位置(只要应用程序打开或最小化)?这是 Loopt 的一个限制,它无法在后台抓取这些位置 - 因此应用程序中的整个“ping”操作。

Currently, phone gap doesn't have this as an option. There are many requests out there for this sort of thing, but I think people are getting tripped up by the TOS for background events for iOS. Regardless, a phone gap plugin would do it as @Chase mentioned, but of course that requires native code writing.

I'm assuming you're wanting to push geo locations every x seconds/minutes so that your server knows where the phone is at any point in time (as long as the app is open or minimized)? That's one limitation of Loopt, is that it can't grab those locations in the background - hence the whole 'ping' action in the app.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文