Use of SVProgressHUD in share extension

本小妞迷上赌 提交于 2019-12-24 19:23:34

问题


I use SVProgressHUD in an iOS app and it's working perfectly. I'd like to use it also for the share extension of this app but it does not show app. I'm using a custom view for the share extension view and here is the code I use to call SVProgressHUD. Note that printing the upload progress works fine. What am I doing wrong? Thanks.

class ShareViewController: UIViewController {
        ...
        Alamofire.upload(multipartFormData: { multipartFormData in
            multipartFormData.append(jpgImageData!, withName: "file",fileName: fname, mimeType: "image/jpg")
            for (key, value) in parameters {
                multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
            }
        },
                         to:url!)
        { (result) in
            switch result {
            case .success(let upload, _, _):

                upload.uploadProgress(closure: { (progress) in
                    print("Upload Progress: \(progress.fractionCompleted)")
                    SVProgressHUD.setViewForExtension(self.view)
                    SVProgressHUD.showProgress(Float(progress.fractionCompleted))
                })
                upload.responseJSON { response in
                if response.response?.statusCode == 200{
                    if let result = response.result.value {
                        DispatchQueue.main.async(execute: {

                            let pre = NSLocale.preferredLanguages[0]
                            var message = "Message"
                            SVProgressHUD.showSuccess(withStatus: message)
                            SVProgressHUD.dismiss(withDelay: 2)
                            self.extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
         })      

}

回答1:


try this

class ShareViewController: UIViewController {
...
Alamofire.upload(multipartFormData: { multipartFormData in
multipartFormData.append(jpgImageData!, withName: "file",fileName: fname, mimeType: "image/jpg")
for (key, value) in parameters {
multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
}
},
to:url!)
{ (result) in
switch result {
case .success(let upload, _, _):

upload.uploadProgress(closure: { (progress) in
print("Upload Progress: \(progress.fractionCompleted)")
 DispatchQueue.main.async(execute: {
SVProgressHUD.setViewForExtension(self.view)
SVProgressHUD.showProgress(Float(progress.fractionCompleted))
})
})
...
}


来源:https://stackoverflow.com/questions/44758062/use-of-svprogresshud-in-share-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!