0
我想在我的模型類中使用ASIHTTPRequest或ASIFormDataRequest。 我該如何委託或檢測請求狀態並返回值。模型類中的ASIHTTPRequest異步請求
例如:
我有一個控制器有IBAction DoIt:發件人。我想調用連接器 - > DoIt,並在連接成功或失敗時回撥我的控制器。
我該如何處理?
謝謝。
我想在我的模型類中使用ASIHTTPRequest或ASIFormDataRequest。 我該如何委託或檢測請求狀態並返回值。模型類中的ASIHTTPRequest異步請求
例如:
我有一個控制器有IBAction DoIt:發件人。我想調用連接器 - > DoIt,並在連接成功或失敗時回撥我的控制器。
我該如何處理?
謝謝。
回調(來自documentation):
- (IBAction)grabURLInBackground:(id)sender
{
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
// Use when fetching binary data
NSData *responseData = [request responseData];
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
}
基於塊:
- (IBAction)grabURLInBackground:(id)sender
{
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
// Use when fetching text data
NSString *responseString = [request responseString];
// Use when fetching binary data
NSData *responseData = [request responseData];
}];
[request setFailedBlock:^{
NSError *error = [request error];
}];
[request startAsynchronous];
}
你讀過嗎? http://allseeing-i.com/ASIHTTPRequest/How-to-use也不要使用ASIHTTP,幾年來它幾乎已經死了。 AFNetworking現在是網絡圖書館。 – jbat100