iOS Developer

Swift常用的技巧

2017-07-02  本文已影响32人  dispath_once
    func uploadfile(_ url :String,par :Dictionary<String,Any>? = nil,filedata :Data? = nil,fileName :String = "iamge.png", call :NetWorkFinishCall?){
        Alamofire.upload(multipartFormData: { (MultipartFormData) in
            if filedata != nil{
                MultipartFormData.append(filedata!, withName: "file", fileName: fileName, mimeType: "image/png");
            }
            if par != nil{
                for (key,value) in par!{
                    MultipartFormData.append((value as! String).data(using: .utf8)!, withName: key)
                }
            }
        }, to:NetWorkTool.shareInstance.BaseUrl! + APPDefine.APIDefine.register) { (result) in
            switch result{
            case .success(let upload,_,_):
                upload.responseJSON(completionHandler: { (data) in
                    if let block = call{
                        if let error = data.error{
                        }
                        let jsonObj = JSON(data:data.data!)
                        block((data.error == nil),jsonObj,data.error)
                    }
                })
                break
            case .failure(let error):
                if let block = call{
                    block(false,nil,error)
                }
                break
            }
        }
    }
上一篇下一篇

猜你喜欢

热点阅读