ios - 在共享扩展中使用 SVProgressHUD

标签 ios swift share-extension svprogresshud

我在 iOS 应用程序中使用 SVProgressHUD,它运行良好。我也想将它用于此应用程序的共享扩展,但它不显示应用程序。 我正在使用共享扩展 View 的自定义 View ,这是我用来调用 SVProgressHUD 的代码。请注意,打印上传进度效果很好。 我究竟做错了什么? 谢谢。

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))
})
})
...
}

关于ios - 在共享扩展中使用 SVProgressHUD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44758062/

相关文章:

ios - 领英 SDK ios swift

ItemProvider 的 iOS 共享扩展问题无法从照片库中读取

ios - ios:“共享扩展名”不允许我将.txt或.csv文件共享到我的应用

swift - AudioUnit回调与同步 : how to ensure thread safety with GCD

iOS 应用程序和共享扩展使用不同的 Realm 数据库

ios - ASIFormDataRequest POST 不起作用

ios - 从 Cocoapods 安装中删除 -Objc 标志

ios - 以编程方式创建的 View Controller 在显示或推送时有黑色空间

ios - iPad启动图像尺寸?

xcode - 无法使用swift更改uitableviewcell中的字体