Skip to content

Commit

Permalink
Merge pull request #120 from nrbrook/macos-support
Browse files Browse the repository at this point in the history
Macos support
  • Loading branch information
dinesharjani authored Sep 6, 2023
2 parents f047153 + e12f601 commit 85b6bed
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
7 changes: 1 addition & 6 deletions Example/Example/Util/McuMgrPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ public struct McuMgrPackage {
// MARK: - Init

init(from url: URL) throws {
let document = UIDocument(fileURL: url)
guard let fileType = document.fileType else {
throw McuMgrPackage.Error.notAValidDocument
}

switch UTI.from(fileType) {
switch UTI.forFile(url) {
case .bin:
self.images = try Self.extractImageFromBinFile(from: url)
case .zip:
Expand Down
18 changes: 18 additions & 0 deletions Example/Example/Util/UTI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

import Foundation
import UniformTypeIdentifiers
#if os(macOS)
import AppKit
#else
import UIKit
#endif

// MARK: - UTI

Expand All @@ -33,4 +38,17 @@ enum UTI: String, CaseIterable {
$0.typeIdentifiers.contains(fileType)
}
}

private static func typeOf(_ url: URL) -> String? {
#if os(macOS)
return try? NSWorkspace.shared.type(ofFile: url.path)
#else
let document = UIDocument(fileURL: url)
return document.fileType
#endif
}

static func forFile(_ file: URL) -> UTI? {
return typeOf(file).flatMap({ from($0) })
}
}
1 change: 1 addition & 0 deletions iOSMcuManagerLibrary.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Pod::Spec.new do |s|
s.swift_versions = ["4.2", "5.0", "5.1", "5.2", "5.3", "5.4", "5.5", "5.6", "5.7"]

s.ios.deployment_target = "9.0"
s.osx.deployment_target = "10.13"

s.source_files = "Source/**/*.{swift, h}"
s.exclude_files = "Source/*.plist"
Expand Down

0 comments on commit 85b6bed

Please sign in to comment.