No callback while using UIDocumentPickerViewController












0















I'm using UIDocumentPickerViewController to select a document from the iPhone.



I have implemented the feature in the following way.



class Si3EntityDocumentViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UIDocumentInteractionControllerDelegate, UIDocumentPickerDelegate, UINavigationControllerDelegate, UIDocumentMenuDelegate {

override func viewDidLoad() {
super.viewDidLoad()
setLoader()
getDocuments(id:entity.id)
let button = UIButton(frame: CGRect(x: 100, y: 100, width: 100, height: 50))
button.backgroundColor = .red
button.setTitle("Upload Doc", for: .normal)
button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
self.view.addSubview(button)
// Do any additional setup after loading the view.
}

@objc func buttonAction(sender: UIButton!){
let documentPicker = UIDocumentPickerViewController(documentTypes: [String(kUTTypeText),String(kUTTypeContent),String(kUTTypeItem),String(kUTTypeData)], in: .import)
documentPicker.delegate = self
present(documentPicker, animated: true, completion: {
documentPicker.delegate = self
} )
}

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
print(urls)
}

}


The func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt url: URL) method has been deprecated in iOS 11 so i have replaced it with func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL])



For some reason, I'm not getting the callback in func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL])



I also have some other code in this class but I've not included it.
When I select a document or click cancel I get the following error in the console




[DocumentManager] The view service did terminate with error: Error
Domain=_UIViewServiceErrorDomain Code=1 "(null)"
UserInfo={Terminated=disconnect method}




I know I'm missing out something very silly, any help is appreciated.



Thanks in anticipation.










share|improve this question



























    0















    I'm using UIDocumentPickerViewController to select a document from the iPhone.



    I have implemented the feature in the following way.



    class Si3EntityDocumentViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UIDocumentInteractionControllerDelegate, UIDocumentPickerDelegate, UINavigationControllerDelegate, UIDocumentMenuDelegate {

    override func viewDidLoad() {
    super.viewDidLoad()
    setLoader()
    getDocuments(id:entity.id)
    let button = UIButton(frame: CGRect(x: 100, y: 100, width: 100, height: 50))
    button.backgroundColor = .red
    button.setTitle("Upload Doc", for: .normal)
    button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
    self.view.addSubview(button)
    // Do any additional setup after loading the view.
    }

    @objc func buttonAction(sender: UIButton!){
    let documentPicker = UIDocumentPickerViewController(documentTypes: [String(kUTTypeText),String(kUTTypeContent),String(kUTTypeItem),String(kUTTypeData)], in: .import)
    documentPicker.delegate = self
    present(documentPicker, animated: true, completion: {
    documentPicker.delegate = self
    } )
    }

    func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
    print(urls)
    }

    }


    The func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt url: URL) method has been deprecated in iOS 11 so i have replaced it with func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL])



    For some reason, I'm not getting the callback in func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL])



    I also have some other code in this class but I've not included it.
    When I select a document or click cancel I get the following error in the console




    [DocumentManager] The view service did terminate with error: Error
    Domain=_UIViewServiceErrorDomain Code=1 "(null)"
    UserInfo={Terminated=disconnect method}




    I know I'm missing out something very silly, any help is appreciated.



    Thanks in anticipation.










    share|improve this question

























      0












      0








      0


      1






      I'm using UIDocumentPickerViewController to select a document from the iPhone.



      I have implemented the feature in the following way.



      class Si3EntityDocumentViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UIDocumentInteractionControllerDelegate, UIDocumentPickerDelegate, UINavigationControllerDelegate, UIDocumentMenuDelegate {

      override func viewDidLoad() {
      super.viewDidLoad()
      setLoader()
      getDocuments(id:entity.id)
      let button = UIButton(frame: CGRect(x: 100, y: 100, width: 100, height: 50))
      button.backgroundColor = .red
      button.setTitle("Upload Doc", for: .normal)
      button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
      self.view.addSubview(button)
      // Do any additional setup after loading the view.
      }

      @objc func buttonAction(sender: UIButton!){
      let documentPicker = UIDocumentPickerViewController(documentTypes: [String(kUTTypeText),String(kUTTypeContent),String(kUTTypeItem),String(kUTTypeData)], in: .import)
      documentPicker.delegate = self
      present(documentPicker, animated: true, completion: {
      documentPicker.delegate = self
      } )
      }

      func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
      print(urls)
      }

      }


      The func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt url: URL) method has been deprecated in iOS 11 so i have replaced it with func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL])



      For some reason, I'm not getting the callback in func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL])



      I also have some other code in this class but I've not included it.
      When I select a document or click cancel I get the following error in the console




      [DocumentManager] The view service did terminate with error: Error
      Domain=_UIViewServiceErrorDomain Code=1 "(null)"
      UserInfo={Terminated=disconnect method}




      I know I'm missing out something very silly, any help is appreciated.



      Thanks in anticipation.










      share|improve this question














      I'm using UIDocumentPickerViewController to select a document from the iPhone.



      I have implemented the feature in the following way.



      class Si3EntityDocumentViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UIDocumentInteractionControllerDelegate, UIDocumentPickerDelegate, UINavigationControllerDelegate, UIDocumentMenuDelegate {

      override func viewDidLoad() {
      super.viewDidLoad()
      setLoader()
      getDocuments(id:entity.id)
      let button = UIButton(frame: CGRect(x: 100, y: 100, width: 100, height: 50))
      button.backgroundColor = .red
      button.setTitle("Upload Doc", for: .normal)
      button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
      self.view.addSubview(button)
      // Do any additional setup after loading the view.
      }

      @objc func buttonAction(sender: UIButton!){
      let documentPicker = UIDocumentPickerViewController(documentTypes: [String(kUTTypeText),String(kUTTypeContent),String(kUTTypeItem),String(kUTTypeData)], in: .import)
      documentPicker.delegate = self
      present(documentPicker, animated: true, completion: {
      documentPicker.delegate = self
      } )
      }

      func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
      print(urls)
      }

      }


      The func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt url: URL) method has been deprecated in iOS 11 so i have replaced it with func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL])



      For some reason, I'm not getting the callback in func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL])



      I also have some other code in this class but I've not included it.
      When I select a document or click cancel I get the following error in the console




      [DocumentManager] The view service did terminate with error: Error
      Domain=_UIViewServiceErrorDomain Code=1 "(null)"
      UserInfo={Terminated=disconnect method}




      I know I'm missing out something very silly, any help is appreciated.



      Thanks in anticipation.







      ios swift4 uidocumentpickervc






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 '18 at 10:20









      Vedant ShirkeVedant Shirke

      1




      1
























          2 Answers
          2






          active

          oldest

          votes


















          0














          You can have a look at the Apple documentation for a better understanding.



          The default behaviour of a UIDocumentPickerViewController is to pick one document and you would have to use:



          func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
          }


          If you are using the UIDocumentPickerViewController to pick multiple documents, then you will have to set the allowsMultipleSelection property to true and implement



          func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
          }


          Also, the following line would suffice.



          present(documentPicker, animated: true)





          share|improve this answer


























          • func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { } has been deprecated for iOS 11. So using documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { } makes no sense. Also I tried setting allowsMultipleSelection doesn't help.

            – Vedant Shirke
            Nov 20 '18 at 11:11













          • Then please refer the documentation. I gave you code snippets that I have used and are working, tested on a device before posting.

            – Prashant
            Nov 20 '18 at 11:31











          • developer.apple.com/documentation/uikit/…

            – Prashant
            Nov 20 '18 at 11:39











          • Also, if a solution works for you (as more than one are posted), kindly select it as the accepted answer, it helps other users.

            – Prashant
            Nov 20 '18 at 11:41



















          0














          I Used this Methods in swift 3



          func openImportDocumentPicker() {
          let documentPicker = UIDocumentPickerViewController(documentTypes: ["public.item"], in: .import)
          documentPicker.delegate = self
          documentPicker.modalPresentationStyle = .formSheet
          self.present(documentPicker, animated: true, completion: { _ in })
          }

          func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
          if controller.documentPickerMode == .import {
          let alertMessage: String = "Successfully imported (url.absoluteURL)"
          }
          }

          func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
          print("Cancelled")
          }





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390825%2fno-callback-while-using-uidocumentpickerviewcontroller%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You can have a look at the Apple documentation for a better understanding.



            The default behaviour of a UIDocumentPickerViewController is to pick one document and you would have to use:



            func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
            }


            If you are using the UIDocumentPickerViewController to pick multiple documents, then you will have to set the allowsMultipleSelection property to true and implement



            func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
            }


            Also, the following line would suffice.



            present(documentPicker, animated: true)





            share|improve this answer


























            • func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { } has been deprecated for iOS 11. So using documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { } makes no sense. Also I tried setting allowsMultipleSelection doesn't help.

              – Vedant Shirke
              Nov 20 '18 at 11:11













            • Then please refer the documentation. I gave you code snippets that I have used and are working, tested on a device before posting.

              – Prashant
              Nov 20 '18 at 11:31











            • developer.apple.com/documentation/uikit/…

              – Prashant
              Nov 20 '18 at 11:39











            • Also, if a solution works for you (as more than one are posted), kindly select it as the accepted answer, it helps other users.

              – Prashant
              Nov 20 '18 at 11:41
















            0














            You can have a look at the Apple documentation for a better understanding.



            The default behaviour of a UIDocumentPickerViewController is to pick one document and you would have to use:



            func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
            }


            If you are using the UIDocumentPickerViewController to pick multiple documents, then you will have to set the allowsMultipleSelection property to true and implement



            func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
            }


            Also, the following line would suffice.



            present(documentPicker, animated: true)





            share|improve this answer


























            • func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { } has been deprecated for iOS 11. So using documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { } makes no sense. Also I tried setting allowsMultipleSelection doesn't help.

              – Vedant Shirke
              Nov 20 '18 at 11:11













            • Then please refer the documentation. I gave you code snippets that I have used and are working, tested on a device before posting.

              – Prashant
              Nov 20 '18 at 11:31











            • developer.apple.com/documentation/uikit/…

              – Prashant
              Nov 20 '18 at 11:39











            • Also, if a solution works for you (as more than one are posted), kindly select it as the accepted answer, it helps other users.

              – Prashant
              Nov 20 '18 at 11:41














            0












            0








            0







            You can have a look at the Apple documentation for a better understanding.



            The default behaviour of a UIDocumentPickerViewController is to pick one document and you would have to use:



            func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
            }


            If you are using the UIDocumentPickerViewController to pick multiple documents, then you will have to set the allowsMultipleSelection property to true and implement



            func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
            }


            Also, the following line would suffice.



            present(documentPicker, animated: true)





            share|improve this answer















            You can have a look at the Apple documentation for a better understanding.



            The default behaviour of a UIDocumentPickerViewController is to pick one document and you would have to use:



            func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
            }


            If you are using the UIDocumentPickerViewController to pick multiple documents, then you will have to set the allowsMultipleSelection property to true and implement



            func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
            }


            Also, the following line would suffice.



            present(documentPicker, animated: true)






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 20 '18 at 11:04

























            answered Nov 20 '18 at 10:57









            PrashantPrashant

            182112




            182112













            • func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { } has been deprecated for iOS 11. So using documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { } makes no sense. Also I tried setting allowsMultipleSelection doesn't help.

              – Vedant Shirke
              Nov 20 '18 at 11:11













            • Then please refer the documentation. I gave you code snippets that I have used and are working, tested on a device before posting.

              – Prashant
              Nov 20 '18 at 11:31











            • developer.apple.com/documentation/uikit/…

              – Prashant
              Nov 20 '18 at 11:39











            • Also, if a solution works for you (as more than one are posted), kindly select it as the accepted answer, it helps other users.

              – Prashant
              Nov 20 '18 at 11:41



















            • func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { } has been deprecated for iOS 11. So using documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { } makes no sense. Also I tried setting allowsMultipleSelection doesn't help.

              – Vedant Shirke
              Nov 20 '18 at 11:11













            • Then please refer the documentation. I gave you code snippets that I have used and are working, tested on a device before posting.

              – Prashant
              Nov 20 '18 at 11:31











            • developer.apple.com/documentation/uikit/…

              – Prashant
              Nov 20 '18 at 11:39











            • Also, if a solution works for you (as more than one are posted), kindly select it as the accepted answer, it helps other users.

              – Prashant
              Nov 20 '18 at 11:41

















            func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { } has been deprecated for iOS 11. So using documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { } makes no sense. Also I tried setting allowsMultipleSelection doesn't help.

            – Vedant Shirke
            Nov 20 '18 at 11:11







            func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { } has been deprecated for iOS 11. So using documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { } makes no sense. Also I tried setting allowsMultipleSelection doesn't help.

            – Vedant Shirke
            Nov 20 '18 at 11:11















            Then please refer the documentation. I gave you code snippets that I have used and are working, tested on a device before posting.

            – Prashant
            Nov 20 '18 at 11:31





            Then please refer the documentation. I gave you code snippets that I have used and are working, tested on a device before posting.

            – Prashant
            Nov 20 '18 at 11:31













            developer.apple.com/documentation/uikit/…

            – Prashant
            Nov 20 '18 at 11:39





            developer.apple.com/documentation/uikit/…

            – Prashant
            Nov 20 '18 at 11:39













            Also, if a solution works for you (as more than one are posted), kindly select it as the accepted answer, it helps other users.

            – Prashant
            Nov 20 '18 at 11:41





            Also, if a solution works for you (as more than one are posted), kindly select it as the accepted answer, it helps other users.

            – Prashant
            Nov 20 '18 at 11:41













            0














            I Used this Methods in swift 3



            func openImportDocumentPicker() {
            let documentPicker = UIDocumentPickerViewController(documentTypes: ["public.item"], in: .import)
            documentPicker.delegate = self
            documentPicker.modalPresentationStyle = .formSheet
            self.present(documentPicker, animated: true, completion: { _ in })
            }

            func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
            if controller.documentPickerMode == .import {
            let alertMessage: String = "Successfully imported (url.absoluteURL)"
            }
            }

            func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
            print("Cancelled")
            }





            share|improve this answer




























              0














              I Used this Methods in swift 3



              func openImportDocumentPicker() {
              let documentPicker = UIDocumentPickerViewController(documentTypes: ["public.item"], in: .import)
              documentPicker.delegate = self
              documentPicker.modalPresentationStyle = .formSheet
              self.present(documentPicker, animated: true, completion: { _ in })
              }

              func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
              if controller.documentPickerMode == .import {
              let alertMessage: String = "Successfully imported (url.absoluteURL)"
              }
              }

              func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
              print("Cancelled")
              }





              share|improve this answer


























                0












                0








                0







                I Used this Methods in swift 3



                func openImportDocumentPicker() {
                let documentPicker = UIDocumentPickerViewController(documentTypes: ["public.item"], in: .import)
                documentPicker.delegate = self
                documentPicker.modalPresentationStyle = .formSheet
                self.present(documentPicker, animated: true, completion: { _ in })
                }

                func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
                if controller.documentPickerMode == .import {
                let alertMessage: String = "Successfully imported (url.absoluteURL)"
                }
                }

                func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
                print("Cancelled")
                }





                share|improve this answer













                I Used this Methods in swift 3



                func openImportDocumentPicker() {
                let documentPicker = UIDocumentPickerViewController(documentTypes: ["public.item"], in: .import)
                documentPicker.delegate = self
                documentPicker.modalPresentationStyle = .formSheet
                self.present(documentPicker, animated: true, completion: { _ in })
                }

                func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
                if controller.documentPickerMode == .import {
                let alertMessage: String = "Successfully imported (url.absoluteURL)"
                }
                }

                func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
                print("Cancelled")
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 '18 at 11:19









                sukh.iossukh.ios

                11




                11






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390825%2fno-callback-while-using-uidocumentpickerviewcontroller%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

                    How to change which sound is reproduced for terminal bell?

                    Can I use Tabulator js library in my java Spring + Thymeleaf project?