gpt4 book ai didi

iOS越狱-如何在后台获取位置

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:26:05 28 4
gpt4 key购买 nike

我编写了一个作为守护进程启动的小应用程序。它基本上只会输出手机的 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

因此,如果我在 springboard 之外手动运行应用程序,它可以正常工作并记录 GPS 位置……至少 15-20 秒……然后 springboard 终止应用程序,因为它没有响应——这是预期的行为。

但是,如果我在启动时启动应用程序 (launchDaemon),它也可以正常启动,但永远不会调用委托(delegate)函数“didUpdateToLocation”!!

我使用的是 iOS 5,所以不确定问题出在哪里。非常感谢任何帮助。

谢谢!!

最佳答案

而不是调用“startUpdatingLocation”,你应该使用startMonitoringSignificantLocationChanges .每当用户的位置发生显着变化时,它都会调用您的应用程序,您将有一些时间进行一些后台处理并确定是否要打开您的应用程序。

如果用户进入您希望监控的某个区域,您还可以让设备调用您的应用。

查看此 question了解更多详情。

关于iOS越狱-如何在后台获取位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9216501/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com