2013-02-21 85 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

相關問題