本文介绍了在共享扩展中使用SVProgressHUD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在iOS应用中使用SVProgressHUD,并且运行良好.我也想将其用于此应用程序的共享扩展名,但它不显示该应用程序.我正在使用共享扩展视图的自定义视图,这是我用来调用SVProgressHUD的代码.请注意,打印上传进度可以正常进行.我究竟做错了什么?谢谢.
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)
})
}
推荐答案
尝试一下
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))
})
})
...
}
这篇关于在共享扩展中使用SVProgressHUD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!