2010-11-03 78 views
0
(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 

} 

我試圖從iPhone將數據發送到Web服務我寫每10分鐘。代碼發送數據,但我不能設置interval.I已註冊使用定位服務在我的應用程序的背景中,所以即使在關閉我的應用程序後,它仍然繼續運行應用程序。任何人都可以建議我應該如何繼續。我是iphone編程的新手。發送GPS數據每10分鐘

回答

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];
+0

非常感謝。看起來像這樣工作。 – agupta 2010-11-03 18:56:09