Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.1.0

- [iOS] Added Swift Package Manager (SPM) support alongside existing CocoaPods support

## 3.0.3

- [Android] Updated compileSdkVersion to 36, Gradle to 8.14 and Java/Kotlin compatibility to version 17
Expand Down
1 change: 1 addition & 0 deletions ios/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ profile

DerivedData/
build/
.build/
GeneratedPluginRegistrant.h
GeneratedPluginRegistrant.m

Expand Down
4 changes: 0 additions & 4 deletions ios/Classes/FlutterFileDialogPlugin.h

This file was deleted.

8 changes: 0 additions & 8 deletions ios/Classes/FlutterFileDialogPlugin.m

This file was deleted.

19 changes: 9 additions & 10 deletions ios/flutter_file_dialog.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
#
Pod::Spec.new do |s|
s.name = 'flutter_file_dialog'
s.version = '0.0.1'
s.summary = 'A new flutter plugin project.'
s.version = '3.1.0'
s.summary = 'Dialogs for picking and saving files in iOS.'
s.description = <<-DESC
A new flutter plugin project.
A Flutter plugin providing dialogs for picking and saving files on iOS.
DESC
s.homepage = 'http://example.com'
s.homepage = 'https://github.com/kineapps/flutter_file_dialog'
s.license = { :file => '../LICENSE' }
s.author = { 'Your Company' => 'email@example.com' }
s.author = { 'KineApps' => 'https://github.com/kineapps' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.source_files = 'flutter_file_dialog/Sources/flutter_file_dialog/**/*.swift'
s.dependency 'Flutter'
s.platform = :ios, '10.0'
s.platform = :ios, '12.0'

# Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
s.swift_version = '5.0'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
s.swift_version = '5.9'
end
17 changes: 17 additions & 0 deletions ios/flutter_file_dialog/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// swift-tools-version: 5.9
import PackageDescription

let package = Package(
name: "flutter_file_dialog",
platforms: [
.iOS(.v12)
],
products: [
.library(name: "flutter-file-dialog", targets: ["flutter_file_dialog"])
],
targets: [
.target(
name: "flutter_file_dialog"
)
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import Flutter
import UIKit

public class SwiftFlutterFileDialogPlugin: NSObject, FlutterPlugin {
public class FlutterFileDialogPlugin: NSObject, FlutterPlugin {
public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "flutter_file_dialog", binaryMessenger: registrar.messenger())
let instance = SwiftFlutterFileDialogPlugin()
let instance = FlutterFileDialogPlugin()
registrar.addMethodCallDelegate(instance, channel: channel)
}

deinit {
writeLog("SwiftFlutterFileDialogPlugin.deinit")
writeLog("FlutterFileDialogPlugin.deinit")
}

var openFileDialog: OpenFileDialog?
Expand Down Expand Up @@ -82,7 +82,7 @@ struct OpenFileDialogParams {
default:
sourceType = .photoLibrary
}

allowEditing = data["allowEditing"] as? Bool ?? false

allowedUtiTypes = data["allowedUtiTypes"] as? [String]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.

import Flutter
import Foundation
import MobileCoreServices
import UIKit
Expand Down Expand Up @@ -106,54 +107,43 @@ class OpenFileDialog: NSObject, UIDocumentPickerDelegate, UIImagePickerControlle

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
picker.dismiss(animated: true, completion: nil)
if #available(iOS 11.0, *) {
if !params!.allowEditing, let pickedFileUrl: URL = info[UIImagePickerController.InfoKey.imageURL] as? URL {
writeLog("picked file: " + pickedFileUrl.absoluteString)
handlePickedFile(pickedFileUrl)
} else {
if let pickedImage: UIImage = info[UIImagePickerController.InfoKey.editedImage] as? UIImage ??
info[UIImagePickerController.InfoKey.originalImage] as? UIImage
{
// save picked image to temp dir
DispatchQueue.global(qos: .userInitiated).async {
do {
let directory = NSTemporaryDirectory()

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyyMMddHHmmss"

let fileName = dateFormatter.string(from: Date()) + ".jpg"

let destinationFileUrl = NSURL.fileURL(withPathComponents: [directory, fileName])!

let jpeg = pickedImage.jpegData(compressionQuality: CGFloat(1.0))!
try jpeg.write(to: destinationFileUrl)

// return picked file path
DispatchQueue.main.async {
writeLog("Saved picked image to: " + destinationFileUrl.path)
self.flutterResult?(destinationFileUrl.path)
}
} catch {
DispatchQueue.main.async {
writeLog(error.localizedDescription)
self.flutterResult?(FlutterError(code: "file_copy_error",
message: error.localizedDescription,
details: nil))
}
if !params!.allowEditing, let pickedFileUrl: URL = info[UIImagePickerController.InfoKey.imageURL] as? URL {
writeLog("picked file: " + pickedFileUrl.absoluteString)
handlePickedFile(pickedFileUrl)
} else {
if let pickedImage: UIImage = info[UIImagePickerController.InfoKey.editedImage] as? UIImage ??
info[UIImagePickerController.InfoKey.originalImage] as? UIImage
{
// save picked image to temp dir
DispatchQueue.global(qos: .userInitiated).async {
do {
let directory = NSTemporaryDirectory()

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyyMMddHHmmss"

let fileName = dateFormatter.string(from: Date()) + ".jpg"

let destinationFileUrl = NSURL.fileURL(withPathComponents: [directory, fileName])!

let jpeg = pickedImage.jpegData(compressionQuality: CGFloat(1.0))!
try jpeg.write(to: destinationFileUrl)

DispatchQueue.main.async {
writeLog("Saved picked image to: " + destinationFileUrl.path)
self.flutterResult?(destinationFileUrl.path)
}
} catch {
DispatchQueue.main.async {
writeLog(error.localizedDescription)
self.flutterResult?(FlutterError(code: "file_copy_error",
message: error.localizedDescription,
details: nil))
}
}
} else {
flutterResult?(nil)
}
}
} else {
// Fallback on earlier versions
DispatchQueue.main.async {
writeLog("iOS 11 or higher required")
self.flutterResult?(FlutterError(code: "minimum_target",
message: "iOS 11 or higher required",
details: nil))
} else {
flutterResult?(nil)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.

import Flutter
import Foundation
import UIKit

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_file_dialog
description: Dialogs for picking and saving files in Android and in iOS.
version: 3.0.3
version: 3.1.0
homepage: https://github.com/kineapps/flutter_file_dialog
repository: https://github.com/kineapps/flutter_file_dialog

Expand Down