1

gps座標をサーバーに送信するアプリケーションを作成しています。30秒ごとに座標を送信する必要があります。ボタンを使用してその送信要求を開始していますが、要求されたとおりに30秒ごとに座標を再送信するタイマーまたはループプロセスを取得できません。何か案は?役立つコードを投稿する:

-(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];
 }

これは、アプリのボタンを押してリクエストを開始するために使用しているコードです。そのボタンを押した後、1つのリクエストだけでなく、アプリを終了するまで、または別のボタンを押してリクエストの送信を停止するまで、30秒ごとに多くのリクエストを送信することは可能ですか?

前もって感謝します!

4

1 に答える 1

2

使用NSTimer

[NSTimer scheduledTimerWithTimeInterval:30.0 target:self selector:@selector(request:) userInfo:nil repeats:YES];
于 2012-10-25T09:24:20.587 に答える