我的代码:
NSMutableArray *sstr = [[DBModel database]getCName];
NSArray *aarr = [[sstr objectAtIndex:0] componentsSeparatedByString:@"!"];
acName = [aarr objectAtIndex:0];
acMobileno = [aarr objectAtIndex:1];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http:///userstatus.php?name=%@&mobileno=%@&status=off",[aarr objectAtIndex:0],[aarr objectAtIndex:1]]];
NSMutableURLRequest *postRequest = [[NSMutableURLRequest alloc]initWithURL:url];
[postRequest setHTTPMethod:@"POST"];
NSString *stringBoundary = @"------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",stringBoundary];
[postRequest addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *postBody = [NSMutableData data];
//name
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"name\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"%@",[aarr objectAtIndex:0]] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
//mobileno
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"mobileno\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"%@",[aarr objectAtIndex:1]] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
//status
NSString *status = @"off";
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"status\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"%@",status] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postRequest setHTTPBody:postBody];
NSData *returndata=[NSURLConnection sendSynchronousRequest:postRequest returningResponse:nil error:nil];
NSString *string1=[[NSString alloc]initWithData:returndata encoding:NSUTF8StringEncoding];
NSLog(@"OFF Status report = %@",string1);
我正在使用performSelectorInBackground:
indidEnterBackground
方法运行此代码。
有时它会给我一个奇怪的问题,即不更新服务器中的表。
使用performSelector
委托方法有问题还是应该将此请求更改为异步?