After asihttprequest releases a message that is no longer maintained, afnetworking will be a good choice if we do not use CDN.
Bottom site: https://github.com/AFNetworking/AFNetworking
After the download, you can directly access the xcode project and use it. Remember to add systemconfiguration. framework.
Example reference:
Add afnetworkactivityindicatormanager to application: didfinishlaunchingwitexceptions.
Remember
# Import "afnetworkactivityindicatormanager. H"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES;}
This is a common download network resource (in JSON format)
Remember
# Import "afhttpclient. H"
# Import "afhttprequestoperation. H"
# Import "jsonkit. H"
Nsurl * url = [nsurl urlwithstring: @ "http://www.domain.com"]; afhttpclient * httpclient = [[afhttpclient alloc] initwithbaseurl: url]; nsstring * _ Path = [nsstring stringwithformat: @ "/user_login/% @/", username, password]; nsmutableurlrequest * request = [httpclient requestwithmethod: @ "Post" Path: _ path parameters: Nil]; [httpclient release]; afhttprequestoperation * operation = [[afhttprequestoperation alloc] initwithrequest: request]; [operation duration: ^ (afhttprequestoperation * operation, Id responseobject ){// After the download is successful, use jsonkit to convert the string to nsdictionary or nsarray formatNsdictionary * deserializeddata = [operation. responsestring objectfromjsonstring];} failure: ^ (afhttprequestoperation * operation, nserror * error ){// Handle download failure}]; Nsoperationqueue * queue = [[nsoperationqueue alloc] init] autorelease]; [queue addoperation: Operation];
After completing the previous step, we will get the absolute address of some images, and download the images asynchronously based on these URLs.
Remember # import "uiimageview + afnetworking. H"
The simple method is
[Imageview setimagewithurl: @ "absolute path of image"];
Complex operations: You can trigger some events after the image is downloaded.
Nsurl * url = [nsurl urlwithstring: @ image absolute path "]; nsmutableurlrequest * request = [required requestwithurl: URL cachepolicy: Required timeoutinterval: 30.0]; [imageview failed: Request placeholderimage: nil success: ^ (nsurlrequest * request, nshttpurlresponse * response, uiimage * image) {nslog (@ "image downloaded successfully! Do something ");} failure: ^ (nsurlrequest * request, nshttpurlresponse * response, nserror * error) {nslog (@ image download successful! Do something "") ;}]; ""
From: http://blog.csdn.net/nogodoss/article/details/8243316