0

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

}
radar
  • 500
  • 1
  • 6
  • 24
  • Did you add the target for SVProgressHud? – Rajesh73 Jun 26 '17 at 12:04
  • No I did not. How can I do that? Thanks. – radar Jun 26 '17 at 12:19
  • If you would have added SVProgressHud manually, then select SVprogressHud.m and tick the share extension target on Right Side Panel, Utillities -> Target MemberShip – Rajesh73 Jun 26 '17 at 12:32
  • Sorry I did not get your point. I added SVprogressHud in my podfile. So I assume that I don't need to add it, right? – radar Jun 26 '17 at 12:34
  • Please refer this, https://stackoverflow.com/a/31989172/4611751 – Rajesh73 Jun 26 '17 at 12:35
  • Thanks Rajesh but I already run `pod install`. BTW, my podfile is as follows: ` use_frameworks! target 'appName' do pod 'SVProgressHUD', '~> 2.1.2' pod 'Alamofire', '~> 4.0' pod 'FileKit', '~> 4.0.1' target 'appNameShareExtension' do inherit! :search_paths end end ` – radar Jun 26 '17 at 12:37
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/147651/discussion-between-radar-and-rajesh73). – radar Jun 26 '17 at 19:33

1 Answers1

0

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))
})
})
...
}
  • Thanks for your answer. Unfortunately, it does not show up neither. I forgot to mention that I'm already using a `DispatchQueue.main.async` further to use SVProgressHUD to display a message. I edit the code for that. – radar Jun 26 '17 at 11:17