问题
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