// AFHTTPClient.h
//
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import <Foundation/Foundation.h>
#import "AFURLConnectionOperation.h"
#import <Availability.h>
/**
`AFHTTPClient` captures the common patterns of communicating with an web application over HTTP. It encapsulates information like base URL, authorization credentials, and HTTP headers, and uses them to construct and manage the execution of HTTP request operations.
## Automatic Content Parsing
Instances of `AFHTTPClient` may specify which types of requests it expects and should handle by registering HTTP operation classes for automatic parsing. Registered classes will determine whether they can handle a particular request, and then construct a request operation accordingly in `enqueueHTTPRequestOperationWithRequest:success:failure`.
## Subclassing Notes
In most cases, one should create an `AFHTTPClient` subclass for each website or web application that your application communicates with. It is often useful, also, to define a class method that returns a singleton shared HTTP client in each subclass, that persists authentication credentials and other configuration across the entire application.
## Methods to Override
To change the behavior of all url request construction for an `AFHTTPClient` subclass, override `requestWithMethod:path:parameters`.
To change the behavior of all request operation construction for an `AFHTTPClient` subclass, override `HTTPRequestOperationWithRequest:success:failure`.
## Default Headers
By default, `AFHTTPClient` sets the following HTTP headers:
- `Accept-Language: (comma-delimited preferred languages), en-us;q=0.8`
- `User-Agent: (generated user agent)`
You can override these HTTP headers or define new ones using `setDefaultHeader:value:`.
## URL Construction Using Relative Paths
Both `-requestWithMethod:path:parameters:` and `-multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:` construct URLs from the path relative to the `-baseURL`, using `NSURL +URLWithString:relativeToURL:`. Below are a few examples of how `baseURL` and relative paths interact:
NSURL *baseURL = [NSURL URLWithString:@"http://example.com/v1/"];
[NSURL URLWithString:@"foo" relativeToURL:baseURL]; // http://example.com/v1/foo
[NSURL URLWithString:@"foo?bar=baz" relativeToURL:baseURL]; // http://example.com/v1/foo?bar=baz
[NSURL URLWithString:@"/foo" relativeToURL:baseURL]; // http://example.com/foo
[NSURL URLWithString:@"foo/" relativeToURL:baseURL]; // http://example.com/v1/foo
[NSURL URLWithString:@"/foo/" relativeToURL:baseURL]; // http://example.com/foo/
[NSURL URLWithString:@"http://example2.com/" relativeToURL:baseURL]; // http://example2.com/
Also important to note is that a trailing slash will be added to any `baseURL` without one, which would otherwise cause unexpected behavior when constructing URLs using paths without a leading slash.
## NSCoding / NSCopying Conformance
`AFHTTPClient` conforms to the `NSCoding` and `NSCopying` protocols, allowing operations to be archived to disk, and copied in memory, respectively. There are a few minor caveats to keep in mind, however:
- Archives and copies of HTTP clients will be initialized with an empty operation queue.
- NSCoding cannot serialize / deserialize block properties, so an archive of an HTTP client will not include any reachability callback block that may be set.
*/
#ifdef _SYSTEMCONFIGURATION_H
typedef enum {
AFNetworkReachabilityStatusUnknown = -1,
AFNetworkReachabilityStatusNotReachable = 0,
AFNetworkReachabilityStatusReachableViaWWAN = 1,
AFNetworkReachabilityStatusReachableViaWiFi = 2,
} AFNetworkReachabilityStatus;
#else
#pragma message("SystemConfiguration framework not found in project, or not included in precompiled header. Network reachability functionality will not be available.")
#endif
#ifndef __UTTYPE__
#if __IPHONE_OS_VERSION_MIN_REQUIRED
#pragma message("MobileCoreServices framework not found in project, or not included in precompiled header. Automatic MIME type detection when uploading files in multipart requests will not be available.")
#else
#pragma message("CoreServices framework not found in project, or not included in precompiled header. Automatic MIME type detection when uploading files in multipart requests will not be available.")
#endif
#endif
typedef enum {
AFFormURLParameterEncoding,
AFJSONParameterEncoding,
AFPropertyListParameterEncoding,
} AFHTTPClientParameterEncoding;
@class AFHTTPRequestOperation;
@protocol AFMultipartFormData;
@interface AFHTTPClient : NSObject <NSCoding, NSCopying>
///---------------------------------------
/// @name Accessing HTTP Client Properties
///---------------------------------------
/**
The url used as the base for paths specified in methods such as `getPath:parameters:success:failure`
*/
@property (readonly, nonatomic, strong) NSURL *baseURL;
/**
The string encoding used in constructing url requests. This is `NSUTF8StringEncoding` by default.
*/
@property (nonatomic, assign) NSStringEncoding stringEncoding;
/**
The `AFHTTPClientParameterEncoding` value corresponding to how parameters are encoded into a request body. This is `AFFormURLParameterEncoding` by default.
@warning Some nested parameter structures, such as a keyed array of hashes containing inconsistent keys (i.e. `@{@"": @[@{@"a" : @(1)}, @{@"b" : @(2)}]}`), cannot be unambiguously represented in query strings. It is strongly recommended that an unambiguous encoding, such as `AFJSONParameterEncoding`, is used when posting complicated or nondeterministic parameter structures.
*/
@property (nonatomic, assign) AFHTTPClientParameterEncoding parameterEncoding;
/**
The operation queue which manages operations enqueued by the HTTP client.
*/
@property (readonly, nonatomic, strong) NSOperationQueue *operationQueue;
/**
The reachability status from the device to the current `baseURL` of the `AFHTTPClient`.
@warning This property requires the `SystemConfiguration` framework. Add it in the active target's "Link Binary With Library" build phase, and add `#import <SystemConfiguration/SystemConfiguration.h>` to the header prefix of the project (`Prefix.pch`).
*/
#ifdef _SYSTEMCONFIGURATION_H
@property (readonly, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus;
#endif
/**
Default SSL pinning mode for each `AFHTTPRequestOperation` created by `HTTPRequestOperationWithRequest:success:failure:`.
*/
#ifdef _AFNETWORKING_PIN_SSL_CERTIFICATES_
@property (nonatomic, assign) AFURLConnectionOperationSSLPinningMode defaultSSLPinningMode;
#endif
/**
Whether each `AFHTTPRequestOperation` created by `HTTPRequestOperationWithRequest:success:failure:` should accept an invalid SSL certificate.
If `_AFNETWORKING_ALLOW_INV
没有合适的资源?快使用搜索试试~ 我知道了~
iOS图文混排(模仿新浪微博)
共139个文件
png:86个
m:20个
h:19个
5星 · 超过95%的资源 需积分: 12 2.2k 下载量 90 浏览量
2013-11-05
14:19:04
上传
评论 13
收藏 650KB ZIP 举报
温馨提示
本Demo采用富文本结合正则表达式实现UITableVIew上的图文混排及布局,提供超链接、@、$等功能,完全模仿新浪微博的功能,在数据请求上使用了AFJSONRequest,也使用了图片的异步加载,性能良好,值得学习。
资源推荐
资源详情
资源评论
收起资源包目录
iOS图文混排(模仿新浪微博) (139个子文件)
AFHTTPClient.h 37KB
AFURLConnectionOperation.h 20KB
RegexKitLite.h 16KB
AFHTTPRequestOperation.h 6KB
AFImageRequestOperation.h 6KB
UIImageView+AFNetworking.h 5KB
RCLabel.h 5KB
AFXMLRequestOperation.h 5KB
AFNetworkActivityIndicatorManager.h 4KB
AFJSONRequestOperation.h 4KB
AFPropertyListRequestOperation.h 3KB
AFNetworking.h 2KB
RCViewCell.h 1KB
SDImageView+SDWebCache.h 565B
MainViewController.h 368B
CustomObject.h 359B
MainAppDelegate.h 290B
HtmlString.h 268B
UIImage+imageNamed_Hack.h 263B
Contents.json 442B
Contents.json 333B
RegexKitLite.m 201KB
RCLabel.m 62KB
AFHTTPClient.m 53KB
AFURLConnectionOperation.m 31KB
MainViewController.m 21KB
AFHTTPRequestOperation.m 13KB
AFImageRequestOperation.m 9KB
RCViewCell.m 7KB
UIImageView+AFNetworking.m 6KB
AFXMLRequestOperation.m 6KB
AFJSONRequestOperation.m 6KB
AFPropertyListRequestOperation.m 6KB
AFNetworkActivityIndicatorManager.m 5KB
HtmlString.m 4KB
SDImageView+SDWebCache.m 2KB
MainAppDelegate.m 2KB
CustomObject.m 997B
WeiBoDemoTests.m 647B
UIImage+imageNamed_Hack.m 415B
main.m 350B
project.pbxproj 69KB
WeiBoDemo-Prefix.pch 344B
emotionImage.plist 5KB
WeiBoDemo-Info.plist 1KB
WeiBoDemoTests-Info.plist 688B
xcschememanagement.plist 571B
face11@2x.png 9KB
face7@2x.png 8KB
face12@2x.png 8KB
face3@2x.png 8KB
face59@2x.png 7KB
face10@2x.png 7KB
face4@2x.png 7KB
face9@2x.png 7KB
face8@2x.png 7KB
face2@2x.png 7KB
face6@2x.png 7KB
face62@2x.png 7KB
face67@2x.png 7KB
face5@2x.png 7KB
face31@2x.png 6KB
face42@2x.png 6KB
face32@2x.png 6KB
face40@2x.png 6KB
face1@2x.png 6KB
face50@2x.png 6KB
face61@2x.png 6KB
face29@2x.png 6KB
face64@2x.png 6KB
face37@2x.png 6KB
face26@2x.png 6KB
face19@2x.png 6KB
face73@2x.png 6KB
face49@2x.png 6KB
face41@2x.png 6KB
face36@2x.png 6KB
face65@2x.png 6KB
face35@2x.png 6KB
face51@2x.png 6KB
face53@2x.png 6KB
face66@2x.png 6KB
face17@2x.png 6KB
face27@2x.png 6KB
face47@2x.png 6KB
face44@2x.png 6KB
face33@2x.png 6KB
face39@2x.png 6KB
face55@2x.png 6KB
face38@2x.png 6KB
face70@2x.png 6KB
face43@2x.png 6KB
face34@2x.png 6KB
face30@2x.png 6KB
face28@2x.png 6KB
face57@2x.png 6KB
face63@2x.png 6KB
face77@2x.png 6KB
face54@2x.png 6KB
face56@2x.png 6KB
共 139 条
- 1
- 2
星期八的日出
- 粉丝: 56
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页