【问题标题】:Use of SVProgressHUD in share extension在共享扩展中使用 SVProgressHUD
【发布时间】:2017-06-26 10:51:34
【问题描述】:

我在 iOS 应用中使用 SVProgressHUD,它运行良好。我也想将它用于此应用程序的共享扩展,但它不显示应用程序。 我正在为共享扩展视图使用自定义视图,这是我用来调用 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)
         })      

}

【问题讨论】:

  • 您是否为 SVProgressHud 添加了目标?
  • 不,我没有。我怎样才能做到这一点?谢谢。
  • 如果您要手动添加 SVProgressHud,然后选择 SVprogressHud.m 并勾选右侧面板上的共享扩展目标,实用程序 -> 目标会员
  • 对不起,我没有明白你的意思。我在我的 podfile 中添加了 SVprogressHud。所以我假设我不需要添加它,对吧?

标签: ios swift share-extension svprogresshud


【解决方案1】:

试试这个

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

【讨论】:

  • 感谢您的回答。不幸的是,它也没有出现。我忘了提到我已经在使用DispatchQueue.main.async 进一步使用 SVProgressHUD 来显示消息。我为此编辑代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多