(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
locmanager = [[CLLocationManager alloc] init];
[locmanager setDelegate:self];
[locmanager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
//[locmanager setDistanceFilter:10];
[locmanager startUpdatingLocation];
[window makeKeyAndVisible];
return YES;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLLocationCoordinate2D loc = [newLocation coordinate];
latitude = [NSString stringWithFormat: @"%f", loc.latitude];
longitude= [NSString stringWithFormat: @"%f", loc.longitude];
//Call to the web service for sending data
}
我试图每10分钟从Iphone发送数据到一个Web服务。我写的代码发送数据但我无法设置间隔。我已经注册在我的应用程序中使用后台位置服务所以它继续在我关闭我的应用程序之后运行应用程序。可以有人建议我应该如何进行。我是iphone编程的新手。
答案 0 :(得分:0)
您可以使用以下测试代码;
NSTimer * updateTimer;
updateTimer = [NSTimer timerWithTimeInterval:10 target:self selector:@selector(startUpdating) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:updateTimer forMode:NSDefaultRunLoopMode];
在startUpdating方法中,你必须写下面的语句;
[locmanager startUpdatingLocation];