I am writing an application to send gps coordinates to a server. I need to send coordinates every 30 seconds. I am using a button to initiate that sending request but i cant get a timer or a loop process to resend the coordinates every 30 seconds as i have been asked to do. Any ideas? Posting some code to help :
-(IBAction)pushedGo:(id)sender
{
NSMutableData *data = [[NSMutableData alloc]init];
self.receivedData = data;
[data release];
NSString *contentType = @"text/html";
NSString *mimeType = @"text/xml";
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://telesto.zapto.org:81/SMART_EdgeNode/EdgeNode/DataFeeds/3/addMeasurement"]];
NSString *string1 = [ NSString stringWithFormat:@"%f", locationController.dblLatitude];
NSString *string2 = [ NSString stringWithFormat:@"%f", locationController.dblLongitude];
NSLog(@"%@",string1);
NSLog(@"%@",string2);
NSString *bodystring =[NSString stringWithFormat:@"geoX#%@#geoY#%@", string1, string2];
NSData *body = [bodystring dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"%@",bodystring);
NSMutableDictionary* headers = [[[NSMutableDictionary alloc] init] autorelease];
[headers setValue:contentType forKey:@"Content-Type"];
[headers setValue:mimeType forKey:@"Accept"];
[headers setValue:@"no-cache" forKey:@"Cache-Control"];
[headers setValue:@"no-cache" forKey:@"Pragma"];
[headers setValue:@"close" forKey:@"Connection"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
[request setHTTPMethod:@"PUT"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:body];
self.conn = [NSURLConnection connectionWithRequest:request delegate:self];
}
That’s the code i am using to initiate request by hitting a button on my app. Is it possible after hitting that button to make it not send just 1 request but sending many requests every 30 seconds till i exit the app or i hit another button to stop the request sending?
Thanks in advance!
Use
NSTimer: