Add iOS Share Extension

This commit is contained in:
Leon Böttger committed 2025-08-17 19:03:47 +02:00
1 parent 13ce7522a7
commit 406247d968
13 files changed
+602 -147

No files matched your search

@@ -198,7 +198,7 @@ class InboundNearbyConnection: NearbyConnection {
} else if let url = URL(string: urlStr) {
#if os(macOS)
NSWorkspace.shared.open(url)
#elseif os(iOS)
#elseif os(iOS) && !EXTENSION
UIApplication.shared.open(url, options: [:], completionHandler: nil)
#endif
}
@@ -18,7 +18,9 @@ import CryptoKit
public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearbyConnectionDelegate, OutboundNearbyConnectionDelegate {
#if !EXTENSION
private let sleepManager = SleepManager.shared
#endif
private var tcpListener: NWListener
private var mdnsServices: [NetService] = []
private var incomingConnections: [String: InboundNearbyConnection] = [:]
+4 -5
View File
@@ -126,15 +126,14 @@ public class SaveFilesManager {
#else
let documentsUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
if let documentsUrl = documentsUrl, let sharedUrl = URL(string: "shareddocuments://\(documentsUrl.path)") {
if UIApplication.shared.canOpenURL(sharedUrl) {
UIApplication.shared.open(sharedUrl, options: [:])
}
#if !EXTENSION
if let documentsUrl = documentsUrl, let sharedUrl = URL(string: "shareddocuments://\(documentsUrl.path)"), UIApplication.shared.canOpenURL(sharedUrl) {
UIApplication.shared.open(sharedUrl, options: [:])
}
else {
showAlert(title: "CouldNotOpenDocumentsFolder", message: "CouldNotOpenDocumentsFolderDescription")
}
#endif
#endif
+68
View File
@@ -0,0 +1,68 @@
//
// Zip.swift
// QuickDrop
//
// Created by Leon Böttger on 11.03.25.
//
import Foundation
class Zip {
static func createAtTemporaryDirectory(zipFilename: String, zipExtension: String = "zip", fromDirectory directoryURL: URL) throws -> URL {
let finalURL = FileManager.default.temporaryDirectory
.appendingPathComponent(zipFilename)
.appendingPathExtension(zipExtension)
return try createAt(
zipFinalURL: finalURL,
fromDirectory: directoryURL
)
}
static func createAt(zipFinalURL: URL, fromDirectory directoryURL: URL) throws -> URL {
guard directoryURL.isDirectory else {
throw CreateZipError.urlNotADirectory(directoryURL)
}
var fileManagerError: Swift.Error?
var coordinatorError: NSError?
let coordinator = NSFileCoordinator()
coordinator.coordinate(readingItemAt: directoryURL, options: .forUploading, error: &coordinatorError) { zipCreatedURL in
do {
// clean if file exists
if FileManager.default.fileExists(atPath: zipFinalURL.path) {
try FileManager.default.removeItem(at: zipFinalURL)
}
try FileManager.default.moveItem(at: zipCreatedURL, to: zipFinalURL)
} catch {
fileManagerError = error
}
}
if let error = coordinatorError ?? fileManagerError {
throw CreateZipError.failedToCreateZIP(error)
}
return zipFinalURL
}
enum CreateZipError: Swift.Error {
case urlNotADirectory(URL)
case failedToCreateZIP(Swift.Error)
}
}
extension URL {
var isDirectory: Bool {
(try? resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory == true
}
}