监视CLLocationManager重大位置更改时,应用不会重新启动-iPhone [英] App won't relaunch when monitoring CLLocationManager significant location changes - iPhone

查看:86
本文介绍了监视CLLocationManager重大位置更改时,应用不会重新启动-iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,该应用程序以用户自己设置的时间间隔(例如,每5分钟)跟踪用户的位置,并通过 ASIHTTPRequest

I am working on an app that keeps track of user's location at a time-interval set by the user himself(e.g. every 5 minutes) and sends it to a server page by ASIHTTPRequest.

此应用应该能够在前台接收更新,无论是在后台还是在应用未运行时(定位服务)。

尽管我的应用程序成功接收了前台和后台的更新,但它似乎在未运行时不会唤醒,也没有向我发送任何请求到服务器。

This app should be able to receive updates on foreground, either on background or even when the app is not running(location services).
Although my app successfully receives updates on the foreground and background, it does not seem to wake up when it is not running and do not send me up any requests to the server.

我正在使用 CLLocationManager 及其委托来执行 startMonitoringSignificantLocationChanges

I am using CLLocationManager and its delegate to perform startMonitoringSignificantLocationChanges for when it is on the background.

设置 中,我的应用程序在定位服务中的图标出现预期的紫色箭头。

On Settings, the icon for my app in Location Services appears with a purple arrow as expected.

在我的 info.plist 上,已将必需的后台模式设置为项目位置根据要求和方法:

On my info.plist, I have Required Background Modes set with an item locations as required and methods:

locationManager:didUpdateToLocation:fromLocation:
locationManager:didFailWithError:

已实现。

我的方法:

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

也已实现,并检查 launchOptions
是否包含 UIApplicationLaunchOptions- LocationKey ,然后开始监视重要的位置,以使其何时应该唤醒/重新启动。

is also implemented and checks whether launchOptions contains UIApplicationLaunchOptions- LocationKey before starting the significant locations monitoring for when it should wake up / relaunch.

有什么办法可以确定我的应用是否真的在重新启动吗?

是否需要设置其他配置才能使其正常工作?

Is there any way I can find out whether my app is really being relaunched?
Is there any extra config that needs to be set in order this to work?

请让我知道是否需要提供其他信息。

Please let me know if I should provide any additional info.

我正在使用的规范:

SDK Xcode 4.2.1

CLLocation在Singleton类内(读som

iOS部署目标:4.3

在Iphone 3GS,4和Xcode的iOS 5模拟器上进行了测试,所有这些设备的行为相同。 >
设备:通用

Specs I am using:
SDK Xcode 4.2.1
CLLocation is inside a Singleton class (read somewhere this might impact)
iOS deployment target: 4.3
Tested on Iphone 3GS,4 and Xcode's iOS 5 simulator, same behavior happens to all of these devices.
Devices:universal

更新

我将代码插入-[UIApplication beginBackgroundTaskWithExpirationHandler:] 并尝试使用 UIBackgroundTaskInvalid 。但是,它甚至似乎都没有输入(BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法。

I inserted my code inside -[UIApplication beginBackgroundTaskWithExpirationHandler:] and tried to check against errors with UIBackgroundTaskInvalid. However, it does not even seem to enter the (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method.

我通过尝试使用SQLite保存和检索数据来跟踪应用程序。在前台和后台执行时,都可以毫无问题地记录数据。当应用未运行时,将不会保存任何数据。

I am keeping track of the app by trying to save and retrieve data by using SQLite. When executing on both foreground and background, it records the data with no problem. When the app is not running, no data is saved at all.

推荐答案

您目前如何检查应用是否重新启动?您在记录什么吗?

How are you currently checking to see if the app relaunches? Are you logging anything?

该应用将重新启动到后台,因此您不会看到自己的应用活跃起来。实际上,它将在一段时间后自动关闭。您可以使用-[UIApplication beginBackgroundTaskWithExpirationHandler:] 做一些工作并请求更多的后台时间。

The app will relaunch to the background, so you won't see your app come alive. It will actually shut down automatically after some time again. You can do some work and request more background time using -[UIApplication beginBackgroundTaskWithExpirationHandler:].

SO上的另一个答案是一些示例代码。根据您的描述,我看不到任何丢失的内容,将您的代码与该项目进行比较,以查看是否丢失了某些内容。

Another answer here on SO posted some example code. From your description I cannot see anything missing, compare your code to that project to see if your missing something.

这篇关于监视CLLocationManager重大位置更改时,应用不会重新启动-iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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