How to send a PDF file using UIActivityViewController

前端 未结 8 1080
野趣味
野趣味 2020-12-13 13:57

I\'m trying to send a PDF using a UIActivityViewController. So far everything works fine using a fairly basic approach but the one issue I have is that when I s

8条回答
  •  隐瞒了意图╮
    2020-12-13 14:32

    For Swift 3

    You have to have a URL array with the path of the PDF you want to send.

    let urlArray = [pdfPath1, pdfPath2]
    

    Then create an UIActivityViewController:

    let activityController = UIActivityViewController(activityItems: urlArray, applicationActivities: nil)
    

    If you are using a UIBarButtonItem to make that action, you can implement this to prevent an error on iPad:

    if let popover = activityController.popoverPresentationController {
       popover.barButtonItem = self.barButtonItem
    }
    

    Finally you have to present the activityController:

    self.present(activityController, animated: true, completion: nil)
    

提交回复
热议问题