簡體   English   中英

iOS越獄 - 如何在后台獲取位置

[英]iOS jailbreak - how to get location in background

我寫了一個小應用程序,它作為一個守護進程啟動。 它基本上只會輸出手機的GPS位置。

main.m:

int main(int argc, char *argv[]) {

NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
LocationController *obj = [[LocationController alloc] init];
[obj getLocation];    
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop run];

[p drain];
return 0;
}

LocationController.m

@implementation LocationController
@synthesize locationManager;

-(id)init {
    self = [super init];
    if(self) {
        trackingGPS = false;
        locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
    }
    return self;
}

-(void)getLocation {
    [locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation     *)newLocation fromLocation:(CLLocation *)oldLocation {
    NSLog(@"NEW LOCATION :: %@", newLocation);
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    NSLog(@"LOCATION ERROR : %@", error);
}

-(void) dealloc {
    [locationManager release];
    [super dealloc];
}
@end

因此,如果我在跳板下手動運行應用程序,它可以正常工作並記錄GPS位置...至少15-20秒...然后跳板終止應用程序,因為它不會重復 - 預期的行為。

但是,如果我在啟動時啟動應用程序(launchDaemon),它也會正常啟動但委托函數'didUpdateToLocation'永遠不會被調用!!

我在iOS 5上,所以不確定問題是什么。 真的很感激任何幫助。

謝謝 !!

您應該使用startMonitoringSignificantLocationChanges ,而不是調用“startUpdatingLocation”。 每當用戶的位置發生顯着變化時,它都會調用您的應用,您將有時間進行后台處理並確定是否要打開您的應用。

如果用戶進入您想要監控的某個區域,您也可以讓設備呼叫您的應用。

有關詳細信息,請參閱此問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM