我正在制作一个调查应用程序,我在开始按钮上将数据上传到服务器,我希望当单击停止按钮时,它应该停止数据上传,这是在以下方法中。
下面是上传按钮开始按钮。
-(IBAction)startSyncButtonAction{
CereniaAppDelegate *appDelegate = (CereniaAppDelegate *)[[UIApplication sharedApplication] delegate];
for (int i=0; i<[appDelegate.coffeeArray count]; i++) {
Coffee *coffeeObj = [appDelegate.coffeeArray objectAtIndex:i];
int mycount=[appDelegate.coffeeArray count];
NSLog(@"My Array count is %d",mycount);
NSString*device_Id=coffeeObj.device_Id;
NSString*R1=coffeeObj.R1;
NSString*R2=coffeeObj.R2;
NSString*R3=coffeeObj.R3;
NSString*comment=coffeeObj.comment;
NSString*update_date_time=coffeeObj.update_date_time;
[appDelegate removeCoffee:coffeeObj];
int mycount1=[appDelegate.coffeeArray count];
NSLog(@"My Array After delete is %d",mycount1);
NSLog(@"device_Id%@",device_Id);
NSLog(@"R1%@",R1);
NSLog(@"R2%@",R2);
NSLog(@"R3%@",R3);
NSLog(@"comment%@",comment);
NSLog(@"update_date_time%@",update_date_time);
NSString *post =[[NSString alloc] initWithFormat:@"device_Id=%@&R1=%@&R2=%@&R3=%@&comment=%@&update_date_time=%@",device_Id,R1,R2,R3,comment,update_date_time];
NSLog(post);
NSURL *url=[NSURL URLWithString:@"http://celeritas-solutions.com/pah_brd_v1/pfizersurvey/SyncSurveySTD.php"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"%@",data);
}
}
-(IBAction)stopButtonAction{
}