其实在创建AFHTTPSessionManager对象的时候用单例创建就行了,因为AFNetWorking的作者写的Demo也是单例创建的。代码如下:
<pre>+(AFHTTPSessionManager *)sharedManager{
static AFHTTPSessionManager * manager;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
manager = [AFHTTPSessionManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.requestSerializer.timeoutInterval = 15.0f;
});
return manager;
}</pre>
网友评论