本文介绍了iphone 应用程序可以在后台唤醒以进行显着的位置更改进行网络活动吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款应用,该应用可在后台监控重大位置变化.我一直在阅读有关 ios4 和应用程序生命周期的所有答案(好吧,我想所有!),但我无法弄清楚的是,当应用程序在后台唤醒时,我是否可以进行任何网络访问由于位置发生重大变化.

I'm working on an app that monitors significant location changes in the background. I've been reading all the answers (well, I think all!) about ios4 and the application lifecycle, but what I can't figure out is whether or not I can do any network access when the app is woken up in the background as a result of a significant location change.

该应用程序当前通过 TCP 套接字进行网络访问.应用程序挂起时套接字将关闭.

The app currently does network access via TCP sockets. The socket is shutdown when the app is suspended.

我是否可以重新连接套接字,接收一些数据,发送新位置,然后在接收位置更改事件的同时仍在后台关闭套接字?在办公室固定不动时很难测试!我们可以假设网络活动的完成时间不到 10 秒.还假设该应用程序未注册为 voip 应用程序(可以/应该是吗?...)

Can I re-connect the socket, receive some data, send the new location and then shutdown the socket all while still in the background as a result of receiving the location change event? It's hard to test while stationary in the office! We can assume that the network activity takes less than 10 seconds to complete. Also assume the app isn't registered as a voip app (could/should it be? ...)

有什么想法吗?

推荐答案

是的.您可以根据重大更改事件进行网络处理.

Yep. You can do your network processing based on significant change events.

当您因重大变化(从终止或暂停状态)而被唤醒进入后台状态时,您可以发出 http 请求.如果您发现您的应用在完成 HTTP 请求之前被终止,您可以通过 beginBackgroundTaskWithExpirationHandler:UIApplication 上的方法.

When you get woken up into the background state on significant change (from terminated or suspended state), you can make your http request. If you find your app is being terminated before you finish your HTTP request, you can ask for additional background processing time via the beginBackgroundTaskWithExpirationHandler: method on UIApplication.

我花了相当多的时间在短途火车上进行测试.:)

I spent a fair bit of time on short train trips to test this out. :)

这篇关于iphone 应用程序可以在后台唤醒以进行显着的位置更改进行网络活动吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:05