#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
时间: 2024-12-25 08:26:24