Tuesday, December 24, 2013

Prudential asynchronous requests can not package a common class? Each page should copy what few ways, I feel a lot of trouble

NSURLConnection asynchronous request can not be encapsulated Cheng a common class?

Prudential asynchronous requests can not package a common class? Each page should copy what few ways, I feel a lot of trouble,

However, if a public class package sincere, and how to notify the requested page returns data?

/ / Send asynchronous get request
- (IBAction) BeginRequest: (NSString *) urlRequest
{


}

- (Void) connection: (NSURLConnection *) connection didReceiveResponse: (NSURLResponse *) response
{
[ReceivedData setLength: 0];
}

/ / Receive data
NSData- (Void) connection: (NSURLConnection *) connection didReceiveData: (NSData *) data
{
[ReceivedData appendData: data];
}
- (Void) connection: (NSURLConnection *) connection didFailWithError: (NSError *) error
{

}
/ / Received, display the results
- (Void) connectionDidFinishLoading: (NSURLConnection *) connection
{



}
Reply:
About http request is recommended to use ASIHTTPRequest
On this type of package is more trouble
First, this class needs to have a set menu, then the need for such an approach similar addDelegate, this method is mainly to add to the current class of this class set the table, and then in the public methods (eg connectionDidFinishLoading), first find the set table the current class, and then call a method of the current class (similar to the method callback)
If the package type is A, the transmission request class is B, B is required to generate the first object A, then A is called addDelegate: self, the B to A with its own set of tables, and then send the request B (like [[ NSURLConnection alloc] initWithRequest: mRequest delegate: A startImmediately: YES] ;) must pay attention to the delegate you want connection set A, if one second after the asynchronous request accordingly, and this time will be called A callback function (eg connectionDidFinishLoading), then First in the callback method to find the set of B, then B is called the callback method, while the value of the pass in the past
Say may be too clear, I do not know if you can understand -
Reply:
Own package a delegate, and then delegate the inside pages with NSInvocation passing different handlers.
Reply:
ASIHTTPRequest asynchronous request also has three methods. With connection almost.
Reply:
I do not agree with the time to copy it, I still feel better to write a parent class. When used in this class can be inherited. Write a program is best to avoid copying and pasting. But maintenance is disastrous
Reply:
reference to the third floor zzxap reply: asynchronous request
ASIHTTPRequest also has three methods. With connection almost.

"About the http request is recommended to use ASIHTTPRequest" I just put a little phrase asi, with the following type of packaging does not matter, I wrote the following in the package is to NSURLConnection callback method, you want the package must have a set, each Before sending a request to join set, but also removed from the set after the end of the callback return value
Reply:
Did not understand the feeling here, specifically for this problem wrote a blog
http://blog.csdn.net/volcan1987/article/details/6685195

No comments:

Post a Comment