How do I do Custom Alert Action Sheet? - ios

I have a mail API which sends some information and document. I send only Files documents but I want to show one more choice in UIDocumentPickerView.
How can I show the list " document , photos , camera etc." in the same picker with images ?
My code is :
#available(iOS 8.0, *)
public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
let urlData = url as URL
let theFile = urlData.absoluteString
self.documentName.text = "\(theFileName)"
}
#available(iOS 8.0, *)
public func documentMenu(_ documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
documentPicker.delegate = self
present(documentPicker, animated: true, completion: nil)
}
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
dismiss(animated: true, completion: nil)
}
func mySpecialFunction(){
let importMenu = UIDocumentMenuViewController(documentTypes: [String(kUTTypePDF)], in: .import)
importMenu.delegate = self
importMenu.modalPresentationStyle = .formSheet
self.present(importMenu, animated: true, completion: nil)
}

It's a custom component, you need to code it yourself of find something similar on GitHub or CocoaControls.

Related

How to add PDF attachment while sending sms in Swift

if (MFMessageComposeViewController.canSendText())
{
let controller = MFMessageComposeViewController()
controller.body = ""
controller.recipients = ["1234567890"]
controller.messageComposeDelegate = self as? MFMessageComposeViewControllerDelegate self.present(controller, animated: true, completion: nil)
}
else
{
print("Cannot send the message")
}
func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult)
{
//Displaying the message screen with animation.
self.dismiss(animated: true, completion: nil)
}
while sending sms i need to attach 2 pdf i know how to add on mail but for sms i haven't found any documentation.
i have used this way for mail but how to do on messaging.
func sendEmail() {
if MFMailComposeViewController.canSendMail() {
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setSubject("Invoice PDF")
do {
let attachmentData = NSData(contentsOfFile: pdfFilePath)
mail.addAttachmentData(attachmentData! as Data, mimeType: "application/pdf", fileName: "InvoicePDF")
mail.mailComposeDelegate = self
present(mail, animated: true)
}
} else {
// show failure alert
}
}
You can export files using the UIActivityViewController:
let activityVC = UIActivityViewController(activityItems: [your-data-here], applicationActivities: nil)
self.present(activityVC, animated: true, completion: nil)
If you want to limit the export options you can use the excludedActivityTypes property.

Multiple selection for document picker controller

I am trying to select multiple files in document picker. Here is my code:
let documentPicker = UIDocumentPickerViewController(documentTypes: [String(kUTTypeFolder)], in: .import)
documentPicker.delegate = self
self.present(documentPicker, animated: false) {
if #available(iOS 11.0, *) {
documentPicker.allowsMultipleSelection = true
}
}
But it is selecting only 1 file at a time. Can anyone suggest me a correct way?
Any help would be highly appreciated!!
Just do it before
self.present
your code should be
let documentPicker = UIDocumentPickerViewController(documentTypes: [String(kUTTypeFolder)], in: .import)
documentPicker.delegate = self
if #available(iOS 11.0, *) {
documentPicker.allowsMultipleSelection = true
}
self.present(documentPicker, animated: false) {
}
and check in Browse tab, not in Recenets tab

How can I get pdf file of ibook in my application?

I want to open document file using swift 4. My requirement is that I want to use document picker. Using Document picker I can upload that file using my application.
In short in my app iIwant other documents like .pdf from device. i had try this .
func documentMenu(_ documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
documentPicker.delegate = self
present(documentPicker, animated: true, completion: nil)
}
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
let myURL = urls
print("import result : \(myURL)")
}
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
print("view was cancelled")
dismiss(animated: true, completion: nil)
}
#IBAction func dsds(_ sender: Any) {
let importMenu = UIDocumentMenuViewController(documentTypes: [String(kUTTypePDF)], in: .import)
importMenu.delegate = self
importMenu.modalPresentationStyle = .formSheet
self.present(importMenu, animated: true, completion: nil)
}

Document Picker View Controller issue in Swift

I have a button in my view controller, when click a button it open a document picker view controller, i have set type like KUTypePDF and KUTypeZipArchive , when i select any of these item from google drive the picker controller gets dismiss and in console it shows a long un finished strings of number that doesn't stop. I'm confused why it is showing that long string. What i want is that after i select any file from google drive it should be shown in my app. I'm getting the file url right. My code is this,
#IBAction func docsBtnTapped(_ sender: Any) {
let importMenu = UIDocumentMenuViewController(documentTypes: [String(kUTTypePDF),String(kUTTypeZipArchive)], in: .import)
importMenu.delegate = self
importMenu.modalPresentationStyle = .fullScreen
self.present(importMenu, animated: true, completion: nil)}
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
let cico = url as URL
print("The Url is : /(cico)", cico)
do {
let weatherData = try NSData(contentsOf: cico, options: NSData.ReadingOptions())
print(weatherData)
let activityItems = [weatherData]
let activityController = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
if UI_USER_INTERFACE_IDIOM() == .phone {
self.present (activityController, animated: true, completion: {
print("Hello")
})
}
else {
let popup = UIPopoverController(contentViewController: activityController)
popup.present(from: CGRect(x: CGFloat(self.view.frame.size.width / 2), y: CGFloat(self.view.frame.size.height / 4), width: CGFloat(0), height: CGFloat(0)), in: self.view, permittedArrowDirections: .any, animated: true)
}
} catch {
print(error)
}
//optional, case PDF -> render
//displayPDFweb.loadRequest(NSURLRequest(url: cico) as URLRequest)
}
func documentMenu(_ documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
documentPicker.delegate = self
present(documentPicker, animated: true, completion: nil)
}
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
print(" cancelled by user")
dismiss(animated: true, completion: nil)
}
This long string come in console when i select any item of PDF or Zip file,
You can use UIDocumentInteractionController to open any kind preview from url:
Here is Simple code to open url:
var documentController:UIDocumentInteractionController!
#IBAction func btnOpenClicked(_ sender: Any) {
if let fileURL = Bundle.main.url(forResource: "icon", withExtension: "jpg") {
// Instantiate the interaction controller
self.documentController = UIDocumentInteractionController.init(url: fileURL)
self.documentController.delegate = self
self.documentController.presentPreview(animated: true)
}
else {
print("File missing! Button has been disabled")
}
}
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return self
}

Importing document with UIDocumentPickerViewController warns "fileprovider plugin was invalidated"

Anytime I import a document via UIDocumentPickerViewController, I see a message logged to the console:
TestApp[66587:1550086] plugin com.apple.UIKit.fileprovider.default invalidated
Does this mean theres something wrong with my code? Or is this just an expected warning? Is there anyway to suppress it?
#IBAction func attachFile(sender: UIButton) {
let documentPicker = UIDocumentPickerViewController(documentTypes: ["public.image"], inMode: .Import)
documentPicker.delegate = self
self.presentViewController(documentPicker, animated: true, completion: nil)
}
func documentPicker(controller: UIDocumentPickerViewController, didPickDocumentAtURL url: NSURL) {
}
I am using xcode 8.3.2 and swift 3.0...Here is my code...it is working well..just call openDocumentPicker() i hope it helps you
extension AddCaseStep3ViewController : UIDocumentMenuDelegate,UIDocumentPickerDelegate{
public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
let url = url as URL
//this is the url of your doc you can send enjoy!!
}
#available(iOS 8.0, *)
public func documentMenu(_ documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
documentPicker.delegate = self
present(documentPicker, animated: true, completion: nil)
}
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
//dismiss(animated: true, completion: nil)
}
func openDocumentPicker(){
//
let documentPicker = UIDocumentPickerViewController(documentTypes: ["public.content","public.data","kUTTypePDF"], in: .import)
documentPicker.delegate = self
documentPicker.modalPresentationStyle = .formSheet
self.present(documentPicker, animated: true, completion: nil)
}}

Resources