Skip to content

Commit

Permalink
refactor: Run SwiftLint
Browse files Browse the repository at this point in the history
  • Loading branch information
koji-1009 committed Dec 14, 2023
1 parent fb75037 commit 53f6bcb
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions ios/Classes/ShareBinaryPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ public class ShareBinaryPlugin: NSObject, FlutterPlugin {
let instance = ShareBinaryPlugin()
registrar.addMethodCallDelegate(instance, channel: channel)
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
guard let args = call.arguments as? [String: Any] else {
result(FlutterError(code: "InvalidArgs", message: "Missing arguments", details: "Expected valid arguments."))
return
}

switch call.method {
case "shareBinary":
guard let bytesTypedData = args["bytes"] as? FlutterStandardTypedData else {
Expand All @@ -24,50 +24,50 @@ public class ShareBinaryPlugin: NSObject, FlutterPlugin {
result(FlutterError(code: "InvalidArgs", message: "filename is invalid", details: "filename must be able to be parsed in swift"))
return
}

let fileManager = FileManager.default
let urls = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)
let cachesDirectoryUrl = urls[0]

let directoryUrl = cachesDirectoryUrl.appendingPathComponent("share_binary", isDirectory: true)
let fileUrl = directoryUrl.appendingPathComponent(filename)

DispatchQueue.global(qos: .background).async {
if !fileManager.fileExists(atPath: directoryUrl.path) {
try? fileManager.createDirectory(atPath: directoryUrl.path, withIntermediateDirectories: true)
}

if fileManager.fileExists(atPath: fileUrl.path) {
try? fileManager.removeItem(atPath: fileUrl.path)
}

fileManager.createFile(atPath: fileUrl.path, contents: bytesTypedData.data)
}

showShareSheet(uri: fileUrl)

result(nil)
case "shareUri":
let uriString = args["uri"] as! String
guard let uri = URL(string: uriString) else {
result(FlutterError(code: "InvalidArgs", message: "URI is invalid", details: "uri must be able to be parsed in swift"))
return
}

showShareSheet(uri: uri)

result(nil)
default:
result(FlutterMethodNotImplemented)
}
}

private func showShareSheet(uri: URL) {
guard let rootViewController = UIApplication.shared.delegate?.window??.rootViewController,
let view = rootViewController.view else {
return
}

let activityViewController = UIActivityViewController(activityItems: [uri], applicationActivities: nil)
if UIDevice.current.userInterfaceIdiom == .pad {
let popoverController = activityViewController.popoverPresentationController
Expand All @@ -79,7 +79,7 @@ public class ShareBinaryPlugin: NSObject, FlutterPlugin {
height: 0
)
}

rootViewController.present(activityViewController, animated: true, completion: nil)
}
}

0 comments on commit 53f6bcb

Please sign in to comment.