我是IOS新手我在用請求完成時的服務器響應來構建http請求。然而,我創建了一個新的對象來處理請求......IOS NSURLConnection和NSthread
至於我可以看到請求處理Asyncronusly這可以確保當請求正在處理
請記住我的應用程序不掛我運行在一個新的對象
-(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];
是BOOL當deligate已經在我的其他類運行NSURLConnections
-(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應用程序正在等待響應,以執行下一個任務的贊助
非常感謝一個解決這個問題!
我覺得這回答您的問題3.任何人:當你異步下載你通常不需要線程。這就是'NSURLConnection'爲你所做的。當你將所有數據加載到'NSURLConnection's [' - (void)connectionDidFinishLoading:(NSURLConnection *)connection'](http://developer.apple.com/library/mac/documentation/)中時,基金會/參考/ NSURLConnectionDelegate_Protocol/Reference/Reference.html#// apple_ref/doc/uid/TP40009947-CH1-BAJHIAJA) – HAS