网络工具类

#import "AFHTTPRequestOperationManager.h"

@interface NetworkTools : AFHTTPRequestOperationManager

+ (instancetype)shareNetworkTools;
@end

#import "NetworkTools.h"

@implementation NetworkTools

+ (instancetype)shareNetworkTools
{
    static id instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSURL *url = [NSURL URLWithString:@"http://xxxxxxx/"];
        instance = [[self alloc] initWithBaseURL:url];
    });
    return instance;
}
@end

#import "AFHTTPSessionManager.h"

@interface NetworkTools2 : AFHTTPSessionManager
+ (instancetype)shareNetworkTools;
@end


#import "NetworkTools2.h"

@implementation NetworkTools2
+ (instancetype)shareNetworkTools
{
    static id instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        // 注意: 在指定baseURL的时候, 后面需要加上/
        NSURL *url = [NSURL URLWithString:@"http://xxxxxxxxx/"];
        instance = [[self alloc] initWithBaseURL:url sessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    });
    return instance;
}
@end

 

posted @ 2016-01-31 09:49  Show撑腰  阅读(149)  评论(0编辑  收藏  举报