how can i let a user pick a local document? - swift

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.

Related

Swift how to reference an image file that is not in *.xcassets folder in storyboard

I was trying to update the icon of my app in LaunchScreen, turned out that the UIImage doesn't update for the situation that a user update from old version to new version, and I searched on web for some solutions, there is one suggesting that I should load image files that are out of the *.xcassets folder, I know how to put the image files to my project root directory, but I don't know how to load it in storyboard, as LaunchScreen.storyboard can't have a view controller class
So my question is: How to reference image files in storyboard
This is the source link: http://arsenkin.com/launch_screen_image_cache.html
You can't use any custom behavior in LaunchScreen.storyboard. And loading images from anywhere except *.xcassets is a custom behavior.
Generally you'd use something like
let path = Bundle.main.path(forResource: "image", ofType: "imageType")
let image = UIImage(contentsOfFile: path!)
to load such an image, but as I've already mentioned, this approach doesn't work for launch screens

Localizing FirebaseUI Auth

I am a swift newbie so please bear with me. I have successfully integrated FirebaseUI into my app. I now wish to localize the strings for Dutch. My whole project is in Dutch so I do not have any localization in the project since it is all hard coded in the storyboard. The FirebaseUI docs say that you should:
// Swift
authUI?.customStringsBundle = NSBundle.mainBundle() // Or any custom bundle.
But I am not sure where to actually place the strings file in the project (or how) or if I should be using a custom bundle?
I have spent a whole day playing around with bundles but without success. Your help would be appreciated!
Here is how I got it to work eventually:
Add a strings file called FirebaseAuthUI.strings. I copied the content of this file from here
Use the following code when you create the controller to handle sign in:
Code:
if let bundlePath = Bundle.main.path(forResource: "FirebaseAuthUI", ofType: "strings") {
let bundle = Bundle(path: bundlePath)
authUI?.customStringsBundle = bundle;
}
Don't forget to translate the strings in step 1.
Good luck

Where should I add my own Markdown file in Vapor project?

I want to add my own Markdown file, a file named profile.md. However, I don't know where I should add the file in my Vapor project, which is developed in Xcode.
I tried adding it to Sources/ or just the root directory, but it cannot be searched by Bundle.main.url(forResource:) function, like:
guard let url = Bundle.main.url(forResource: "profile", withExtension: ".md") else { ... }
Also, I found that I already added it under Copy Bundle Resources tab.
In the normal app (for iOS and macOS), the function above works properly.
How can I add my own file to be used in Vapor project developed in Xcode?
This is a very basic example of loading the contents of a file from a custom location using Foundation rather than Vapor's template view loading mechanism, and returning it as a text response.
drop.get { req in
let templateString = try String(contentsOfFile: drop.workDir + "Resources/profile.md")
return templateString
}
I'm not sure exactly what you mean by "parse, and embed it into another template file" but you'd put that bit in between the lines above.

Handling two document type

I'm developping a mac application that allow to transcribe/subtitles video. I must deal with two kind of document type:
SRT file (read/write)
Video file (read only)
For now SRT is the only document type of my application. I open video with an Open a video... menu item (under File), I connected to the openVideo action of the First responder.
Here is the code of my VideoControlerView called when pressing Open a video... :
#IBAction func openVideo(sender: AnyObject) {
let dlg = NSOpenPanel()
dlg.runModal()
if let url = dlg.URL {
self.playerView.player = AVPlayer(URL: url)
}
}
I'm sure it is possible to benefit from the multi document type handling of document based application but I can't figure how. Any idea?
After questionning Apple Developer support about it, DocumentType is only designed for the editing document (SRT in my case).
The way I handle my asset (video file) is the proper way to go!

Parse and Viewing Files on WebView

I have some files between the extensions of pdf and doc on parse database
I have a tableview which populates from parse query so when i click on them i want to display the file for that row in a new webview. I'm on final stage now but i could not find a way to get file from parse and view it on webview via Swift.
No issue on code so far my tableview populates and cells are making segue to the new empty webview, of course without file. By the way i'm not sure webview can view the doc files so if it can't please advice me the best way to do it.
Thank you
You'll need to retrieve the URL for the file object, and tell the web view to load that URL. Lets assume you have a Place object that has a PFFile related to it via an attribute called brochure. You can get your PFFile object that describes the file (doesn't contain the actual file) with a call like:
let placeBrochure = myPlace["brochure"] as PFFile
Then, you'll need to extract the url from that PFFile
let brochureURL = NSURL(string: placeBrochure.url)! // Probably shouldn't force unwrap
and load it into your webview
let request = NSURLRequest(URL: brochureURL)
webview.loadRequest(request)
For your specific case, you'll need to extract the equivalent of the myPlace object from some sort of array that represents the data that's used to populate your tableview, and this will probably need to happen in didSelectRow.
In terms of support for Microsoft Word .doc format files, it looks like UIWebView should be able to handle them: https://developer.apple.com/library/ios/qa/qa1630/_index.html