【问题标题】:is it possible to track location even if application is not running即使应用程序没有运行,是否可以跟踪位置
【发布时间】:2013-02-21 03:04:02
【问题描述】:

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

【问题讨论】:

标签: iphone ios objective-c ios5 ios6


【解决方案1】:

这是可能的——请参阅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 方法。然后,即使在后台没有完整的后台应用程序,您也可以获得适当的重要位置更新。文档的其他部分指出,重大变化是从一个蜂窝塔到另一个蜂窝塔的任何变化。

【讨论】:

  • 但是如果应用程序没有在后台运行,那有可能吗?
  • 如果您的应用程序不在前台或后台运行,它怎么能做任何事情?
  • 你可以做region monitoring..你注册一个区域(一个点和一个半径),当你来到那个区域时,ios会告诉你......或者离开那个区域......但是我不知道那是你想要的……还是你想在用户移动时跟踪他……
  • 没错,一旦您“进入”或“退出”某个预定义区域,GeoFencing 将打开您的应用程序,但触发通知取决于操作系统,而不是应用程序。
  • 我非常有趣地阅读了您的回答。这是因为问题中明确指出的OP......“不在后台运行”。我以为我会发现一些突破......
【解决方案2】:

如果App在后台,可以在info.plist中添加键值对。键是UIBackgroundModes,值如下:

然后在后台做点什么:

- (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不会运行应用程序的一行代码。

【讨论】:

  • 那这些家伙是怎么做到的呢?请看http://www.stealthgenie.com
  • @user1630200 :) 我看到了。但也许该软件正在后台运行。一个软件不用在内存中运行就可以收集用户信息,这超出了我的想象。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-07-10
  • 1970-01-01
  • 2018-02-18
  • 1970-01-01
  • 2017-02-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多