• z7_895669
  • 48.9MB
  • zip
  • 0
  • VIP专享
  • 0
  • 2022-04-04 07:18
资源来自百度音乐API; 使用oc语言开发; 项目完整,内容丰富,值得学习。
<p align="center" > <img src="" alt="AFNetworking" title="AFNetworking"> </p> [![Build Status](]( AFNetworking is a delightful networking library for iOS and Mac OS X. It's built on top of the [Foundation URL Loading System](, extending the powerful high-level networking abstractions built into Cocoa. It has a modular architecture with well-designed, feature-rich APIs that are a joy to use. Perhaps the most important feature of all, however, is the amazing community of developers who use and contribute to AFNetworking every day. AFNetworking powers some of the most popular and critically-acclaimed apps on the iPhone, iPad, and Mac. Choose AFNetworking for your next project, or migrate over your existing projects—you'll be happy you did! ## How To Get Started - [Download AFNetworking]( and try out the included Mac and iPhone example apps - Read the ["Getting Started" guide](, [FAQ](, or [other articles on the Wiki]( - Check out the [documentation]( for a comprehensive look at all of the APIs available in AFNetworking - Read the [AFNetworking 2.0 Migration Guide]( for an overview of the architectural changes from 1.0. ## Communication - If you **need help**, use [Stack Overflow]( (Tag 'afnetworking') - If you'd like to **ask a general question**, use [Stack Overflow]( - If you **found a bug**, _and can provide steps to reliably reproduce it_, open an issue. - If you **have a feature request**, open an issue. - If you **want to contribute**, submit a pull request. ### Installation with CocoaPods [CocoaPods]( is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like AFNetworking in your projects. See the ["Getting Started" guide for more information]( #### Podfile ```ruby platform :ios, '7.0' pod "AFNetworking", "~> 2.0" ``` ## Requirements | AFNetworking Version | Minimum iOS Target | Minimum OS X Target | Notes | |:--------------------:|:---------------------------:|:----------------------------:|:-------------------------------------------------------------------------:| | 2.x | iOS 6 | OS X 10.8 | Xcode 5 is required. `NSURLSession` subspec requires iOS 7 or OS X 10.9. | | [1.x]( | iOS 5 | Mac OS X 10.7 | | | [0.10.x]( | iOS 4 | Mac OS X 10.6 | | (OS X projects must support [64-bit with modern Cocoa runtime]( > Programming in Swift? Try [Alamofire]( for a more conventional set of APIs. ## Architecture ### NSURLConnection - `AFURLConnectionOperation` - `AFHTTPRequestOperation` - `AFHTTPRequestOperationManager` ### NSURLSession _(iOS 7 / Mac OS X 10.9)_ - `AFURLSessionManager` - `AFHTTPSessionManager` ### Serialization * `<aFURLRequestSerialization rel='nofollow' onclick='return false;'>` - `AFHTTPRequestSerializer` - `AFJSONRequestSerializer` - `AFPropertyListRequestSerializer` * `<aFURLResponseSerialization rel='nofollow' onclick='return false;'>` - `AFHTTPResponseSerializer` - `AFJSONResponseSerializer` - `AFXMLParserResponseSerializer` - `AFXMLDocumentResponseSerializer` _(Mac OS X)_ - `AFPropertyListResponseSerializer` - `AFImageResponseSerializer` - `AFCompoundResponseSerializer` ### Additional Functionality - `AFSecurityPolicy` - `AFNetworkReachabilityManager` ## Usage ### HTTP Request Operation Manager `AFHTTPRequestOperationManager` encapsulates the common patterns of communicating with a web application over HTTP, including request creation, response serialization, network reachability monitoring, and security, as well as request operation management. #### `GET` Request ```objective-c AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager GET:@"" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; ``` #### `POST` URL-Form-Encoded Request ```objective-c AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; NSDictionary *parameters = @{@"foo": @"bar"}; [manager POST:@"" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; ``` #### `POST` Multi-Part Request ```objective-c AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; NSDictionary *parameters = @{@"foo": @"bar"}; NSURL *filePath = [NSURL fileURLWithPath:@"file://path/to/image.png"]; [manager POST:@"" parameters:parameters constructingBodyWithBlock:^(id<aFMultipartFormData rel='nofollow' onclick='return false;'> formData) { [formData appendPartWithFileURL:filePath name:@"image" error:nil]; } success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Success: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; ``` --- ### AFURLSessionManager `AFURLSessionManager` creates and manages an `NSURLSession` object based on a specified `NSURLSessionConfiguration` object, which conforms to `<NSURLSessionTaskDelegate>`, `<NSURLSessionDataDelegate>`, `<NSURLSessionDownloadDelegate>`, and `<NSURLSessionDelegate>`. #### Creating a Download Task ```objective-c NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration]; NSURL *URL = [NSURL URLWithString:@""]; NSURLRequest *request = [NSURLRequest requestWithURL:URL]; NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) { NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil]; return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]]; } completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) { NSLog(@"File downloaded to: %@", filePath); }]; [downloadTask resume]; ``` #### Creating an Upload Task ```objective-c NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; AFURLSessionManager *manager = [[AFURLSess