美文网首页
iOS 自定义AFNetworking

iOS 自定义AFNetworking

作者: 李乙幺 | 来源:发表于2018-08-13 14:03 被阅读14次
    屏幕快照 2018-08-13 下午2.05.44.png
    import UIKit
    import AFNetworking
    enum LEONetWorkRequestType : String  {
        case GET = "GET"
        case POST = "POST"
    }
    class LEONetWorkTools: AFHTTPSessionManager {
        static let shareInstance : LEONetWorkTools = LEONetWorkTools();
    }
    extension LEONetWorkTools{
        
        func loadNetWorkData(requestType:LEONetWorkRequestType, urlString:String,param:Any,finshBlock:@escaping ((_ finshResult:[String : Any]?,_ error:Error?)->())) {
            let successBack = { (task : URLSessionDataTask, result:Any?) in
                finshBlock(result as? [String : Any],nil);
            };
            let filureBack  = { (task : URLSessionDataTask?, error:Error) in
                finshBlock(nil,error);
            };
            if requestType == .GET {
                get(urlString, parameters: param, progress: nil, success: successBack, failure: filureBack);
            }else{
                post(urlString, parameters: param, progress: nil, success: successBack, failure: filureBack);
            }
        }
    }
    //欢迎加入:洛阳iOS开发交流(570890454)
    
    

    相关文章

      网友评论

          本文标题:iOS 自定义AFNetworking

          本文链接:https://www.haomeiwen.com/subject/rjxubftx.html