I would like to send the signed pdf to other's email. How can I do?
My Code:
#objc func handleUploadPDF() {
let fileURL = Bundle.main.bundleURL.appendingPathComponent("Exhibit-A-SAMPLE-CONTRACT.pdf")
let writableURL = copyFileURLToDocumentFolder(fileURL)
let document = PSPDFDocument(url: fileURL)
let configuration = PSPDFConfiguration { builder in
builder.thumbnailBarMode = .scrollable
}
let pdfController = PDFViewController(document: document, configuration: configuration)
present(UINavigationController(rootViewController: pdfController), animated: true, completion:nil)
}
Make sure that you include emailButtonItem in pdfViewController's navigation item's right bar button items array, like so:
#objc func handleUploadPDF() {
let fileURL = Bundle.main.bundleURL.appendingPathComponent("Exhibit-A-SAMPLE-CONTRACT.pdf")
let writableURL = copyFileURLToDocumentFolder(fileURL)
let document = PSPDFDocument(url: fileURL)
let configuration = PSPDFConfiguration { builder in
builder.thumbnailBarMode = .scrollable
}
let pdfController = PDFViewController(document: document, configuration: configuration)
pdfController.navigationItem.setRightBarButtonItems([pdfController.emailButtonItem], animated: false)
present(UINavigationController(rootViewController: pdfController), animated: true, completion:nil)
}
For more details about how to customize the toolbar, please take a look at https://pspdfkit.com/guides/ios/current/customizing-the-interface/customizing-the-toolbar/
In the future, please reach out to our support portal at pspdfkit.com/support/request/ - we're happy to provide support there for our commercial SDK.
Related
This is my code for calling UIDocumentPickerViewController to choose the files for my firmware update which have to be .zip only. When I press on "Select" button, the Document Picker View shows up:
#IBAction func selectButtonAction(_ sender: UIButton) {
if sender.title(for: .normal) == "Select"{
if let controller = (UIApplication.shared.delegate as? AppDelegate)?.currentViewController {
let importMenu = UIDocumentPickerViewController(documentTypes: [String(kUTTypeArchive)], in: .open )
importMenu.delegate = self
importMenu.modalPresentationStyle = .formSheet
controller.present(importMenu, animated: true, completion: nil)
}
} else {
changeDFUItemsDesign(isFileURLNil: true)
}
}
Right now it's possible to open the files in .docx format, but I need to only let the user pick one format - a zip file.
I cannot present what I have done so far because I am not able to find a solution. Is there a way to make a check for a zip file or just forbid selecting other formats? Thank you!
Intialize the DocumentPicker with the list of supported types.
let zip = ["com.pkware.zip-archive"]
let importMenu = UIDocumentPickerViewController(documentTypes: zip, in: .import)
Here's a list of supported UTIs
In my view's extension I use the UIDocumentPickerDelegate and in the function I check if my file's last component is zip:
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
if let fileURL = urls.first, fileURL.pathExtension == "zip" {
self._fileURL = fileURL
self.fileNameLabel.text = _fileURL?.lastPathComponent
} else {
_fileURL = nil
fileNameLabel.text = "Select file"
}
}
I am using UIActivityViewController to export RTF files in my app to iCloud Drive with the help of iOS11's new File App feature.
The relevant code looks like this:
struct MyFileObj {
var name: String = "file10"
var rtfString: String
var rtfURL: URL {
return folderURL.appendingPathComponent(name).appendingPathExtension("rtf")
}
...
...
...
func exportToRTFURL() -> URL? {
let data = rtfString.data(using: .utf8)!
do {
try data.write(to: rtfURL)
} catch {
return nil
}
return rtfURL
}
}
Class MYVC: {
...
...
...
func presentShareUI(_ shareUrls: [URL], sender: Any?) {
let vc = UIActivityViewController(activityItems: shareUrls, applicationActivities: nil)
vc.popoverPresentationController?.permittedArrowDirections = [.right, .left]
vc.popoverPresentationController?.sourceView = sourceView
vc.popoverPresentationController?.sourceRect = CGRect(x: sourceView.frame.width/2, y: sourceView.frame.height / 2, width: 0, height: 0)
vc.preferredContentSize = CGSize(width: 100, height: 100)
present(vc, animated: true) {
self.selectBtn.isEnabled = true
self.fileActionBarBtnItems.forEach { $0.isEnabled = true }
}
}
}
when doing export job, the code looks like this:
let myFileObjc = MyFileObj()
let shareURLs = [myFileObjc.exportToRTFURL()!]
self.presentShareUI(shareURLs, sender: nil)
so far everything works fine, both the file name and its extension ".rtf" shown on the UI:
However, when I actually add it to iCloud Drive, the extension of file type "rtf" disappeared:
The more strange behavior of my code is that when I tap use AirDrop to share, the file will appears in the Download Folder of my MBP with the wanted ".rtf" file extension.
How should I make the same file extension ".rtf" appears also when I export my file to iCloud Drive?
Any help will be appreciate, thanks in advance.
Using SFSafariViewController, works well but for some reason when I go to this webpage [knowitall.ch], it starts up by opening a zoomed view? with a small black box that I need to press to get the full webpage.
My code couldn't be simpler.
if let url = URL(string: url2U) {
let vc = SFSafariViewController(url: url, entersReaderIfAvailable: true)
vc.delegate = self
present(vc, animated: true)
}
If I press the box I get the correct view, how to code around this so I open with the second view here? black box not required :)
That "zoomed view" is the Reader Mode. It shows up because you asked for it. Set entersReaderIfAvailable to false if you don't want it. Also, init(url:entersReaderIfAvailable:) has been deprecated in iOS 11. You need to initialize it with a config object:
if let url = URL(string: url2U) {
let vc: SFSafariViewController
if #available(iOS 11.0, *) {
let config = SFSafariViewController.Configuration()
config.entersReaderIfAvailable = false
vc = SFSafariViewController(url: url, configuration: config)
} else {
vc = SFSafariViewController(url: url, entersReaderIfAvailable: false)
}
vc.delegate = self
present(vc, animated: true)
}
I'm developing a loan related app where user upload his documents like pay-slips, it-returns, etc. For that I should show the user all the documents he/she having in his/her iPhone. How to show a picker for documents?
UIDocumentPickerViewController is what you are looking for.
You init one with a list of document types you want to be able to pick, and a mode, which is usually .open to get access to a file in a cloud provider directly. You can also use .import which will copy the file to your container instead of giving you access to the file in the cloud provider's container directly, if the goal is just to upload it (you can remove the copy after uploading).
Once you have created your picker, you present it, and implement the delegate method didPickDocumentsAt to retrieve the list of files chosen by the user.
Check out the Particles sample code and this years WWDC session « Managing Documents in your iOS Apps »
just call openDocumentPicker method when you want to upload document in your application..
import MobileCoreServices
func openDocumentPicker() {
let importMenu = UIDocumentMenuViewController(documentTypes: [kUTTypePDF as String], in: .import)
importMenu.delegate = self
self.present(importMenu, animated: true, completion: nil)
}
create your viewcontroller extension
extension ViewController: UIDocumentMenuDelegate {
func documentMenu(_ documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
documentPicker.delegate = self
present(documentPicker, animated: true, completion: nil)
}
func documentMenuWasCancelled(_ documentMenu: UIDocumentMenuViewController) {
print("we cancelled")
dismiss(animated: true, completion: nil)
}
}
extension ViewController: UIDocumentPickerDelegate {
internal func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
do {
let fileAttributes = try FileManager.default.attributesOfItem(atPath: url.path)
let fileSizeNumber = fileAttributes[FileAttributeKey.size] as! NSNumber
let fileSizea = fileSizeNumber.doubleValue
let fileSize = fileSizea/1000000.0
if fileSize > 5.0 {
appDelegate.displayAlert(Title: "", Message: "Selected File are too big,Please select file less than 5.0 mb")
} else {
let documentData = try Data(contentsOf: url, options: .dataReadingMapped)
}
} catch let error {
print(error.localizedDescription)
}
}
}
above this code only you can access pdf if you want to access anpther document than just use this code
/*
let pdf = String(kUTTypePDF)
let spreadsheet = String(kUTTypeSpreadsheet)
let movie = String(kUTTypeMovie)
let aviMovie = String(kUTTypeAVIMovie)
let docs = String(kUTTypeCompositeContent)
let img = String(kUTTypeImage)
let png = String(kUTTypePNG)
let jpeg = String(kUTTypeJPEG)
let txt = String(kUTTypeText)
let zip = String(kUTTypeZipArchive)
let msg1 = String(kUTTypeEmailMessage)
let msg2 = String(kUTTypeMessage)
let types = [pdf, spreadsheet, movie, aviMovie, img, png, jpeg, txt, docs, zip, msg1, msg2]
*/
iOS 11 or later
let importMenu = UIDocumentPickerViewController.init(documentTypes: ["public.item"], in: UIDocumentPickerMode.import)
self.present(importMenu, animated: true) {
}
Please Refer the following link for more description
https://www.techotopia.com/index.php/An_iOS_Document_Browser_Tutorial
iOS 10 or earlier
You can write the below function when your document picker opens. it will work for all the file types which you want to upload.
func openDocumentPicker() {
let importMenu = UIDocumentMenuViewController(documentTypes: ["public.item"], in: .import)
importMenu.delegate = self
importMenu.modalPresentationStyle = .formSheet
self.present(importMenu, animated: true, completion: nil)
}
I have a problem with iCloud file import
I'm getting empty options after I choose the place to import from (iCloud, google drive, dropbox ... etc)
I have data on iCloud drive and the entitlements are right
So what is wrong with this code or is there anything about the settings may cause this problem?
here is the code
#IBAction func selectionButtonAction(_ sender: Any) {
let types = [kUTTypePDF as String ,kUTTypePNG as String, kUTTypeImage as String,kUTTypeJPEG as String]
UINavigationBar.appearance().isTranslucent = true
let documentMenu = UIDocumentMenuViewController(documentTypes: types, in: .import)
documentMenu.delegate = self
self.viewController?.present(documentMenu, animated: true, completion: nil)
}
func documentMenu(_ documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
documentMenu.delegate = self
self.viewController?.present(documentMenu, animated: true, completion: nil)
}
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
if controller.documentPickerMode == .import {
// do staff
}
}
Here is what I get When I run the app on iOS 10
When I Press choose File
then after pressing on iCloud
That's what I get if I run the app on iOS 9:
I'm sure I have data there like here in the iCloud Drive application
And the entitlement
I had the same problem, when trying to present a already used Instance of the UIDocumentMenuViewController.
I was instantiating it lazily like this:
lazy var documentMenuController: UIDocumentMenuViewController = {
let controller = UIDocumentMenuViewController(documentTypes: ["com.adobe.pdf"], in: .import)
controller.delegate = self
return controller
}()
Which produced this error every time except the first time.
So I changed the code to this:
var documentMenuController: UIDocumentMenuViewController {
let controller = UIDocumentMenuViewController(documentTypes: ["com.adobe.pdf"], in: .import)
controller.delegate = self
return controller
}
To obtain a fresh instance on every access of the property.