开发者

Sending coordinates to an URL POST each five minutes

开发者 https://www.devze.com 2023-03-15 12:35 出处:网络
I need to send coordinates to a web server in each five minutes. I\'m doing this way: In the -(void) mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation I have variables

I need to send coordinates to a web server in each five minutes. I'm doing this way:

In the -(void) mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation I have variables (declared in the .h file) receiving the information I want to 开发者_如何学编程send by the post.

And I have a NSTimer calling a method wich initiates this:

{
    ASIFormDataRequest * request = [ASIFormDataRequest requestWithURL:myURL];
    [request setDelegate:self];
    [request setPostValue:myValue forKey:@"myKey"];
    [request addRequestHeader:@"Content-Type" value:[NSString stringWithFormat:@"application/x-www-form-urlencoded; charset=%@", @"UTF-8"]];
    [request startAsynchronous];
}

The app crashes when the timer calls the function to send data.

Anyone, please, can help me?


Based on what code you've given us, the only place the problem can be is in the serialization of myValue. Since we have no idea what that object is, we can't do much other than make broad suggestions. myValue needs to be a string, encoded such that it is safe to submit as a form value. URL encoded, XML, or even JSON would work. RestKit and ObjectiveResource both have good serializer implementations you could base on.

The important thing to realize is that you can't add an arbitrary object to the post values of ASIFormDataRequest unless you've built some plumbing around your objects and ASI* to make it format your objects for HTTP.

0

精彩评论

暂无评论...
验证码 换一张
取 消