From 0cfbc85c979ad3b5fa7e16288953a74109b6d254 Mon Sep 17 00:00:00 2001 From: Ricardo Silva <97543217+OS-ricardomoreirasilva@users.noreply.github.com> Date: Tue, 23 Aug 2022 16:43:13 +0100 Subject: [PATCH] fix: Move Extensions to Main Class (#17) Move the plugin's classes extensions to the main class, in order to avoid conflicts when importing these on Objective C code on an edge case where the project's name has special chars on it. --- CHANGELOG.md | 4 ++++ package.json | 2 +- plugin.xml | 2 +- src/ios/FileViewerErrors.swift | 4 +--- src/ios/FileViewerOpenDocument.swift | 11 ++++------- src/ios/FileViewerPreview.swift | 9 +++------ 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f18cf97..c90c4c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Version 1.0.6] +### Fixes +- Moved the plugin's class extensions to the class itself. (https://outsystemsrd.atlassian.net/browse/RMET-1769) + ## [Version 1.0.5] ### Fixes - Removed hook that adds swift support and added the plugin as dependecy. (https://outsystemsrd.atlassian.net/browse/RMET-1680) diff --git a/package.json b/package.json index 5b09d00..5ea7003 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.outsystems.plugins.fileviewer", - "version": "1.0.5", + "version": "1.0.6", "description": "OutSystems Cordova Plugin to provide the functionality of a file viewer to mobile applications.", "keywords": [ "ecosystem:cordova", diff --git a/plugin.xml b/plugin.xml index e70ab6a..d28c144 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + OSFileViewer OutSystems Cordova Plugin to provide the functionality of a file viewer to mobile applications. OutSystems Inc diff --git a/src/ios/FileViewerErrors.swift b/src/ios/FileViewerErrors.swift index 84d3f07..445394a 100644 --- a/src/ios/FileViewerErrors.swift +++ b/src/ios/FileViewerErrors.swift @@ -7,7 +7,7 @@ import Foundation -enum FileViewerErrors: String, Error { +enum FileViewerErrors: String, Error, LocalizedError { case fileDoesNotExist = "The file you are trying to open does not exist" case emptyFileName = "No file name or/and extension was provided" case couldNotOpenDocument = "Could not open the document" @@ -15,8 +15,6 @@ enum FileViewerErrors: String, Error { 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 { var errorDescription: String? { return NSLocalizedString(rawValue, comment: "") } } diff --git a/src/ios/FileViewerOpenDocument.swift b/src/ios/FileViewerOpenDocument.swift index 87f1b28..0446d71 100644 --- a/src/ios/FileViewerOpenDocument.swift +++ b/src/ios/FileViewerOpenDocument.swift @@ -7,7 +7,7 @@ import UIKit -class FileViewerOpenDocument: NSObject { +class FileViewerOpenDocument: NSObject, UIDocumentInteractionControllerDelegate { var documentInteractionController:UIDocumentInteractionController? weak var viewController: UIViewController? @@ -45,17 +45,14 @@ class FileViewerOpenDocument: NSObject { self.documentInteractionController?.presentPreview(animated: true) } -} - -extension FileViewerOpenDocument: UIDocumentInteractionControllerDelegate { - //MARK: UIDocumentInteractionControllerDelegate + // MARK: - UIDocumentInteractionControllerDelegate + func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController { return self.viewController! } - } -extension URL { +fileprivate extension URL { var uti: String { return (try? self.resourceValues(forKeys: [.typeIdentifierKey]))?.typeIdentifier ?? "public.data" } diff --git a/src/ios/FileViewerPreview.swift b/src/ios/FileViewerPreview.swift index bd88a02..2728430 100644 --- a/src/ios/FileViewerPreview.swift +++ b/src/ios/FileViewerPreview.swift @@ -9,7 +9,7 @@ import Foundation import QuickLook import AVKit -class FileViewerPreview { +class FileViewerPreview: QLPreviewControllerDataSource { lazy var previewItem = NSURL() weak var viewController: UIViewController? @@ -54,15 +54,12 @@ class FileViewerPreview { playerViewController.player!.play() } } - -} -//MARK:- QLPreviewController DataSource -extension FileViewerPreview: QLPreviewControllerDataSource { + // MARK: - QLPreviewController DataSource func numberOfPreviewItems(in controller: QLPreviewController) -> Int { return 1 } - + func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem { return self.previewItem as QLPreviewItem }