我是 IOS 的新手,当请求完成时,我正在构建一个带有来自服务器的响应的 http 请求。然而,我创建了一个新对象来处理请求......
据我所知,请求是异步处理的,这确保我的应用程序在处理请求时不会挂起
请记住,我在新对象中运行此请求
-(void)signup
{
NSLog(@"Signeduop");
//placing all the form fields in an array
NSArray *fieldsArray;
NSArray *keysArryay;
keysArryay = [NSArray arrayWithObjects:
[NSString stringWithFormat:@"e_mail"],
[NSString stringWithFormat:@"MobileNo"],
[NSString stringWithFormat:@"DeviceType"],
[NSString stringWithFormat:@"AppleKey"],
[NSString stringWithFormat:@"FamilyKey"],
[NSString stringWithFormat:@"ServiceCompany"],
[NSString stringWithFormat:@"First_Name"],
[NSString stringWithFormat:@"Last_Name"],
[NSString stringWithFormat:@"ID"],
nil];
fieldsArray = [NSArray arrayWithObjects:
[NSString stringWithFormat:@"%@",txt_email.text],
[NSString stringWithFormat:@"%@",txt_telNo.text],
[NSString stringWithFormat:@"APPLE"],
[NSString stringWithFormat:@"PlaceheldforKey"],
[NSString stringWithFormat:@"%@",txt_familyKey.text],
[NSString stringWithFormat:@"%@",txt_serviceKey.text],
[NSString stringWithFormat:@"%@",txt_firstname.text],
[NSString stringWithFormat:@"%@",txt_lastname.text],
[NSString stringWithFormat:@"%@",txt_id.text]
,nil];
NSDictionary *ValKeyDic = [NSDictionary dictionaryWithObjects:fieldsArray forKeys:keysArryay];
NSError *error1 = [NSError alloc];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:ValKeyDic options:NSJSONWritingPrettyPrinted error:&error1];
NSString *jstring = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@" ===== %@", jstring);
HttpClass * hy = [HttpClass alloc];
NSInteger varx = 45;
[hy setMode:(int *)55];
//[hy AppWayRegistration:(NSInteger *)varx : jstring] ;
dispatch_queue_t Queue = dispatch_queue_create("com.plump___________", 0);
//dispatch_queue_t high = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0);
//dispatch_set_target_queue(Queue);
dispatch_sync(Queue, ^{ [hy AppWayRegistration:(NSInteger *)varx : jstring]; });
//dispatch_d Queue);
int d =hy.RegistrationSucceededMethod;
NSLog(@"%d joooono",d);
[hy RegistrationSucceededMethod];
//NSLog(@"J -- %d",[hy RegistrationSucceededMethod]);
}
代码运行后,它应该为子类 [hy RegistrationSucceededMethod] 设置一个布尔值;
当 NSURLConnections deligate 在我的其他类中运行时设置了该布尔值
-(void)connectionDidFinishLoading: (NSURLConnection *) connection
{
//do something with the data
NSLog(@"Suckceeded! recieved %d bytes of data",[recieveData length]);
RegistrationSucceeded = TRUE ;
//[self RegistrationSucceededMethod];
}
我的问题是如何在调用对象之前等待线程完成网络操作(即线程完成)
我的第二个问题是线程知道 connectionDidFinishLoading 作为它在对象中的一个 deligate 方法,它是否在该线程上运行
我的第三个问题是处理 http 请求响应的正常方式是什么,您的 ios 应用程序正在等待该响应以执行下一个任务
非常感谢解决这个问题的人!