2010-11-03 6 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 

} 

J'essaie d'envoyer des données d'Iphone à un service Web toutes les 10 minutes.Le code que j'ai écrit envoie les données, mais je ne peux pas définir l'intervalle.J'ai enregistré pour utiliser les services de localisation en arrière-plan dans mon application, donc il continue à courir l'application même après que je ferme mon application.Peut-on me suggérer comment dois-je procéder.Je suis nouveau à la programmation iphone.Envoyer les données GPS Toutes les 10 minutes

Répondre

0

vous pouvez utiliser le code de test suivant;

NSTimer * updateTimer;


updateTimer = [NSTimer timerWithTimeInterval:10 target:self selector:@selector(startUpdating) userInfo:nil repeats:YES]; 
[[NSRunLoop mainRunLoop] addTimer:updateTimer forMode:NSDefaultRunLoopMode]; 

Dans la méthode startUpdating, vous devez écrire l'instruction ci-dessous;


[locmanager startUpdatingLocation];
+0

Merci beaucoup.Comme cela fonctionne. – agupta

Questions connexes