2013-02-21 39 views
2

在一个iPhone应用程序的位置,是可以跟踪的位置,并将其发送到服务器,即使有权限位置的应用程序没有在后台运行。是可以跟踪即使应用程序没有运行

+1

我没有答案,但我可以肯定地说这是可能的,你可能无法将该应用程序提交给appstore。 – 2013-02-21 03:05:44

+0

[我如何在iOS应用程序中每隔n分钟更新一次背景位置?](http://stackoverflow.com/questions/6347503/how-do-i-get-a-background-location-update -every-n-minutes-in-my-ios-application) – Monolo 2013-02-22 19:23:44

回答

5

这是可能的 - 见this document对于一般的多任务处理,这section of the Location Awareness Programming Guide for "Getting Location Events in the Background"。当然,所有这些都讨论了iOS设备可以获取您的位置的各种方式(手机信号塔三角测量,Skyhook式WiFi网络观测和GPS),而不是专用GPS。

总之,从读那些文档:添加UIBackgroundModes钥匙插入你的info.plist,这是一个数组,并把值“位置”进去。即使在后台,您也会收到CLLocationManager更新。

但是,如果你想成为不错的电池,那么你最好使用一个CLLocationManager的startMonitoringSignificantLocationChanges方法。那么即使在后台应用程序中,即使在后台应用程序中,您也可以获得适当的位置更新。文件的其他部分指出,重要的改变是从一个电池塔到另一个电池塔的任何改变。

+0

但是,如果应用程序没有在后台运行,那么它有可能吗? – 2013-02-21 03:20:05

+0

如果您的应用程序未在前台或背景上运行,该怎么做? – Ares 2013-02-21 03:22:29

+0

你可以做[区域监测](http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html)..你在哪里注册一个区域(一个点一个半径),ios会告诉你什么时候你来到那个区域..或者离开那个区域...但是我不知道你是否想要..或者你想追踪用户,因为他沿着它移动。 – chuthan20 2013-02-21 03:23:10

3

如果应用程序在后台运行,你可以在info.plist中添加键值对。关键是UIBackgroundModes和值象下面这样:

enter image description here

然后做一些背景:

- (void)applicationDidEnterBackground:(UIApplication *)application 
{ 
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 

    UIDevice *device = [UIDevicecurrentDevice]; 
    BOOL backgroundSupported = NO; 
    if ([device respondsToSelector:@selector(isMultitaskingSupported)]) { 
     backgroundSupported = YES; 
    } 

    __blockUIBackgroundTaskIdentifier bgTaskId = [application beginBackgroundTaskWithExpirationHandler:^{ 
     [application endBackgroundTask:bgTaskId]; 
     bgTaskId = UIBackgroundTaskInvalid; 
    }]; 

    if (backgroundSupported) { 
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
      // 
     }); 
    } 
} 

但是,如果应用程序是不是即使在背景,即,不是在内存,那么应用程序可以做什么? CPU不会运行应用程序的一行代码。

+0

那么这些人怎么做呢?请参阅[http://www.stealthgenie.com](http://www.stealthgenie.com) – 2013-02-21 04:51:13

+0

@ user1630200 :)我看到了。但是也许软件在后台运行。我无法想象软件可以收集用户信息而无需在内存中运行。 – 2013-02-21 05:20:36

相关问题