Skip to content

Commit

Permalink
Merge pull request #15 from OutSystems/fix/RMET-1474/no-file-extensio…
Browse files Browse the repository at this point in the history
…n-error

RMET-1474 iOS show error when file has no extension
  • Loading branch information
nflsilva authored Mar 31, 2022
2 parents 14b2666 + 3eb13ea commit f6100a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ios/FileViewerErrors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum FileViewerErrors: String, Error {
case invalidURL = "The URL you are trying to open is malformed"
case invalidEmptyURL = "Path of the file to open is either null or empty"
case downloadFailed = "The download failed"
case missingFileExtension = "The file has no extension"
}

extension FileViewerErrors : LocalizedError {
Expand Down
6 changes: 5 additions & 1 deletion src/ios/FileViewerPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class FileViewerPlugin {

if let url = urlString {
if let file = URL.init(string: url) {

let fileName = file.lastPathComponent
guard fileName.contains(".") else { throw FileViewerErrors.missingFileExtension }

guard FileManager.default.fileExists(atPath: file.path) else { throw FileViewerErrors.fileDoesNotExist }

if let viewController = rootViewController {
Expand All @@ -40,7 +44,7 @@ class FileViewerPlugin {
return completion({ throw FileViewerErrors.invalidURL })
}

if let fileUrl = URL(string: url), let viewController = rootViewController {
if let fileUrl = URL(string: url.replacingOccurrences(of: " ", with: "%20")), let viewController = rootViewController {
let fileViewerOpenDocument = FileViewerOpenDocument(viewController: viewController)
fileViewerOpenDocument.openDocumentFromUrl(url:fileUrl, completion: { (inner: ErrorCompletionHandler) -> Void in
do {
Expand Down

0 comments on commit f6100a7

Please sign in to comment.