I'm sharing a PDF using the built in Share activity action sheet using the following code:
if let pdf = pdfData {
let vc = UIActivityViewController(activityItems: [pdf], applicationActivities: [])
if (vc.responds(to: #selector(getter: popoverPresentationController))) {
vc.popoverPresentationController?.sourceView = btnShare;
}
self.present(vc, animated: true)
} else {
showTextAlertWithImage...
...
}
When the sharing popover is displayed, tapping on Airdrop and sharing to a nearby computer the PDF everything works as expected.
But if I choose Mail from the sharing list the PDF is blank. Does anyone please know why?
It's the same PDF that's being shared in both situations. If it matters, the mail account is an Outlook account.
Sharing the PDF through the Gmail app also produces the correct PDF, however the attachment does not include the '.pdf' file extension.
Check how to add Content Type to your activity item you are sharing.
Related
I'm supposed to test PSPDFKit in a way that lets the user open a locally saved pdf file.
For this i require the files url(e.g. path, i guess). How can i let the user pick a local document?
Can anybody help me out?
I'm using storyboard and swift.
You can present a PDF document in PSPDFKit using the PDFViewController like so:
// Create the `Document`.
let fileURL = Bundle.main.url(forResource: "Document", withExtension: "pdf")!
let document = Document(url: fileURL)
// Create the PDF view controller.
let pdfController = PDFViewController(document: document)
// Present the PDF view controller within a `UINavigationController` to enable the toolbar.
present(UINavigationController(rootViewController: pdfController), animated: true)
For more details, take a look at the following guide here.
Also, to present a document that your end-user has selected, consider using a document picker or a file browser. Please refer to DocumentPickerSidebarExample.swift from Catalog and SwiftUI Document Browser for runnable example projects.
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.
This question already has answers here:
How to write a file to a folder located at Apple's Files App in Swift
(2 answers)
Closed 3 years ago.
I just created a PDF document in my app and I want to save the document on the device in a way that the "Files" app can access the saved document.
When you download a PDF document in Safari there is an option to save the document to the "Files" app, which is what I'm trying to do.
I Googled for several hours but wasn't able to find any useful methods.
If you have access to your PDFdata then you could present the user with a UIActivityViewController where they can then save it to Files, or share it with any of the other available options:
let activityViewController = UIActivityViewController(activityItems: ["Name To Present to User", pdfData], applicationActivities: nil)
present(activityViewController, animated: true, completion: nil)
Minimum of iOS 11
The Files app was introduced in iOS 11. You will not be presented with the option to save to Files when you are on a version less than iOS 11. With that being said, documents can be downloaded to a variety of different apps depending on the settings available on the user's phone and the options you allow.
#available(iOS 11.0, *)
func savePDF() {
guard let documentData = document.dataRepresentation() else { return }
let activityController = UIActivityViewController(activityItems: [documentData], applicationActivities: nil)
self.present(activityController, animated: true, completion: nil)
}
This is an example of a way to save a document. You can't force it to be downloaded and show up in their Files app. You have to present a UIActivityViewController that shows options on what they can do with that document.
If you want to exclude any options shown on the UIActivityViewController, then implement excludedActivityTypes like so.
activityController.excludedActivityTypes = [.airDrop, .postToTwitter]
Try UIDocumentInteractionController:
let doc = UIDocumentInteractionController(url: url)
doc.presentOptionsMenu(from:in:animated:)
There's an option named save to Files.
When i open an attachment from iPhone or iPad mail application, there is a popup that can transfert the file to a third party application.
This iOS popup is called UIActivityViewController.
I wand to add my own iOS application (written in swift) in this popup and i do not know how to do...
Thanks
I believe you are asking about two separate things.
UIActivityViewController:
Here's my code in my app.
let vc = UIActivityViewController(activityItems: [shareImage], applicationActivities: [])
vc.excludedActivityTypes = [
UIActivityType.airDrop,
UIActivityType.assignToContact,
UIActivityType.addToReadingList,
//UIActivityType.copyToPasteboard,
//UIActivityType.mail,
//UIActivityType.message,
//UIActivityType.openInIBooks,
//UIActivityType.postToFacebook,
//UIActivityType.postToFlickr,
UIActivityType.postToTencentWeibo,
//UIActivityType.postToTwitter,
UIActivityType.postToVimeo,
UIActivityType.postToWeibo,
UIActivityType.print,
//UIActivityType.saveToCameraRoll
]
present(vc,
animated: true,
completion: nil)
vc.popoverPresentationController?.sourceView = self.view
vc.completionWithItemsHandler = {(activity, success, items, error) in
}
Pay attention to the excludedActiviyTypes code. My app is an image effect app, so I commented out the things I wish to have in the popup - Weibo, print, assignToContact, ReadingList, Vimeo, and TencentWeibo. Here's the thing - I kept the full list of activities for quick reference. (I've never found it on ADC and end up getting it by using code complete.)
UIActivityType is an extended struct, so if you want to go the route of using it this way I think you'll have to (1) subclass UIActivityViewController, (2) write your own extension to UIActivityType, and (3) provide any/all code needed to use a service that isn't listed above.
A Document Provider is what I think you are looking for. Either that, or Universal - sometimes called Deep - Linking. (The links are to Apple documentation for using each.)
I've obviously used UIActivityiewController, but haven't (yet) had any need to these other two.
If you have questions about setting up a UIActivityViewController, post them in the comments. If someone else has a way to "extend" it in any way other than I described, let me know and I'll remove this answer.
I am using the following code to share text using iOS sharing extension (UIActivityViewController).
let vc = UIActivityViewController(activityItems: ["File URL"], applicationActivities: [])
presentViewController(vc, animated: true, completion: nil)
It shows a popup to share using text sharing applications like following:
But, I want the sharing app portion in my view into a page control like below:
How can I do this? If there is any alternative way to achieve this requirement, kindly suggest.
I have created a stand-alone HTML, CSS, JavaScript offline map view using Leaflet (see leafletjs.com). I can use FileApp/DiskAid to download the application to the iphone. I can tap on the HTML file and view the app, but as you can see from the attached screen shot, the layers and zoom controls are at the top of the screen. If I try and press them then your HTML viewer with block the press and slide down a banner (BACK, ACTIONS, etc) (the black top banner that your viewer shows).
Better yet, I would like to open it with SAFARI since it has the NITRO JS engine, but the only OPEN IN options I get are Evernote, RiddleDocs, Mover, and DropBox.
Is there way to tell safari or chrome for IOS to open up a local file system where the html is: http:// 127.0.0.1/fileApp/Toby.html for example where Toby is my HTML file? I realize is somewhere it the data for t
First Step :-
These options are configured using keys in your Info.plist file. The first key is UIFileSharingEnabled, which enables iTunes sharing of files in your Documents folder. The second key is LSSupportsOpeningDocumentsInPlace, which grants the local file provider access to files in your Documents folder. Add these keys to your Info.plist and set their values to YES.
enter image description here
enter image description here
let documentPicker = UIDocumentPickerViewController(documentTypes: [String(kUTTypePDF)], in: .import)
documentPicker.delegate = self
documentPicker.modalPresentationStyle = .overCurrentContext
present(documentPicker, animated: true, completion: nil)
You can use option either to import or export files from app. Also you can define the type of files you want to export or import...