Skip to content
This repository was archived by the owner on Jul 21, 2022. It is now read-only.
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
1 change: 1 addition & 0 deletions example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"esys_flutter_share","path":"/Users/emalware/Documents/GitHub/esys-flutter-share/","dependencies":["path_provider"]},{"name":"path_provider","path":"/Users/emalware/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]}],"android":[{"name":"esys_flutter_share","path":"/Users/emalware/Documents/GitHub/esys-flutter-share/","dependencies":["path_provider"]},{"name":"path_provider","path":"/Users/emalware/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/emalware/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+2/","dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"esys_flutter_share","dependencies":["path_provider"]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]}],"date_created":"2020-05-17 09:26:15.641282","version":"1.17.1"}
18 changes: 18 additions & 0 deletions example/ios/Flutter/Flutter.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# NOTE: This podspec is NOT to be published. It is only used as a local source!
#

Pod::Spec.new do |s|
s.name = 'Flutter'
s.version = '1.0.0'
s.summary = 'High-performance, high-fidelity mobile apps.'
s.description = <<-DESC
Flutter provides an easy and productive way to build and deploy high-performance mobile apps for Android and iOS.
DESC
s.homepage = 'https://flutter.io'
s.license = { :type => 'MIT' }
s.author = { 'Flutter Dev Team' => '[email protected]' }
s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s }
s.ios.deployment_target = '8.0'
s.vendored_frameworks = 'Flutter.framework'
end
12 changes: 12 additions & 0 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/emalware/Documents/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/emalware/Documents/GitHub/esys-flutter-share/example"
export "FLUTTER_TARGET=/Users/emalware/Documents/GitHub/esys-flutter-share/example/lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
export "FLUTTER_FRAMEWORK_DIR=/Users/emalware/Documents/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "TRACK_WIDGET_CREATION=true"
24 changes: 9 additions & 15 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
30CC177B0653FC1250DBBDDC /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9BB236F61766429B48517DC1 /* Pods_Runner.framework */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; };
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
Expand All @@ -27,8 +23,6 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */,
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -38,14 +32,15 @@
/* Begin PBXFileReference section */
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
2E5C0BBD7D62CB710027B3CC /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
3C0A3C2BE03E9F59173D1870 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
8EAD3609D7D7E23B86CA3900 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = "<group>"; };
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand All @@ -59,8 +54,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */,
3B80C3941E831B6300D905FE /* App.framework in Frameworks */,
30CC177B0653FC1250DBBDDC /* Pods_Runner.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -79,16 +72,17 @@
4204C137FD4F389FE8CF8C94 /* Pods */ = {
isa = PBXGroup;
children = (
2E5C0BBD7D62CB710027B3CC /* Pods-Runner.debug.xcconfig */,
3C0A3C2BE03E9F59173D1870 /* Pods-Runner.release.xcconfig */,
8EAD3609D7D7E23B86CA3900 /* Pods-Runner.profile.xcconfig */,
);
name = Pods;
sourceTree = "<group>";
};
9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup;
children = (
3B80C3931E831B6300D905FE /* App.framework */,
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
9740EEBA1CF902C7004384FC /* Flutter.framework */,
9740EEB21CF90195004384FC /* Debug.xcconfig */,
7AFA3C8E1D35360C0083082E /* Release.xcconfig */,
9740EEB31CF90195004384FC /* Generated.xcconfig */,
Expand Down Expand Up @@ -225,15 +219,15 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin";
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
};
53F69E7EBD03F2E7D52A5B83 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework",
"${BUILT_PRODUCTS_DIR}/esys_flutter_share/esys_flutter_share.framework",
"${BUILT_PRODUCTS_DIR}/path_provider/path_provider.framework",
Expand All @@ -246,7 +240,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
9740EEB61CF901F6004384FC /* Run Script */ = {
Expand Down

This file was deleted.

136 changes: 92 additions & 44 deletions ios/Classes/SwiftEsysFlutterSharePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,80 +22,128 @@ public class SwiftEsysFlutterSharePlugin: NSObject, FlutterPlugin {
}

func text(arguments:Any?) -> Void {
// prepare method channel args
// no use in ios
//// let title:String = argsMap.value(forKey: "title") as! String
let argsMap = arguments as! NSDictionary
let text:String = argsMap.value(forKey: "text") as! String

// set up activity view controller
let activityViewController:UIActivityViewController = UIActivityViewController(activityItems: [text], applicationActivities: nil)

// present the view controller
let controller = UIApplication.shared.keyWindow!.rootViewController as! FlutterViewController
activityViewController.popoverPresentationController?.sourceView = controller.view

controller.show(activityViewController, sender: self)
setupAndShow(activityItems: [text], argsMap: argsMap)
}

func file(arguments:Any?) -> Void {
// prepare method channel args
// no use in ios
//// let title:String = argsMap.value(forKey: "title") as! String
let argsMap = arguments as! NSDictionary
let name:String = argsMap.value(forKey: "name") as! String
let text:String = argsMap.value(forKey: "text") as! String

// load the file
let docsPath:String = NSSearchPathForDirectoriesInDomains(.cachesDirectory,.userDomainMask , true).first!;
let contentUri = NSURL(fileURLWithPath: docsPath).appendingPathComponent(name)

// prepare sctivity items
var activityItems:[Any] = [contentUri!];
if(!text.isEmpty){
// add optional text
activityItems.append(text);
}

// set up activity view controller
let activityViewController:UIActivityViewController = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)

// present the view controller
let controller = UIApplication.shared.keyWindow!.rootViewController as! FlutterViewController
activityViewController.popoverPresentationController?.sourceView = controller.view

controller.show(activityViewController, sender: self)
let tempDic: NSMutableDictionary = argsMap.mutableCopy() as! NSMutableDictionary
tempDic["names"] = [name]
files(arguments:tempDic)
}

func files(arguments:Any?) -> Void {
// prepare method channel args
// no use in ios
//// let title:String = argsMap.value(forKey: "title") as! String
let argsMap = arguments as! NSDictionary
let names:[String] = argsMap.value(forKey: "names") as! [String]
let text:String = argsMap.value(forKey: "text") as! String
let mimeType:String = argsMap.value(forKey: "mimeType") as! String

// prepare sctivity items
var activityItems:[Any] = [];

// load the files
for name in names {
let docsPath:String = NSSearchPathForDirectoriesInDomains(.cachesDirectory,.userDomainMask , true).first!;
activityItems.append(NSURL(fileURLWithPath: docsPath).appendingPathComponent(name)!);

//try to convert the file into a JPG/ PNG
if let image = getAsImageContent(path: docsPath, fileName:name, mimeType:mimeType){
activityItems.append(image)
}
else{
activityItems.append(NSURL(fileURLWithPath: docsPath).appendingPathComponent(name)!);
}
}

if(!text.isEmpty){
// add optional text
activityItems.append(text);
}

setupAndShow(activityItems: activityItems, argsMap: argsMap)
}

private func isImageMimeType(mimeType:String) -> Bool
{
if(!mimeType.isEmpty && (mimeType.lowercased() == "image/png" || mimeType.lowercased() == "image/jpg")){
return true;
}

return false;
}

private func getAsImageContent(path: String, fileName: String, mimeType: String) -> Data?
{
//check if file is a valid image mimeType
if(!isImageMimeType(mimeType:mimeType)) {
return nil
}

if(path.isEmpty || fileName.isEmpty){
return nil
}

// set up activity view controller
let activityViewController:UIActivityViewController = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)

// present the view controller
let contentUri = NSURL(fileURLWithPath: path).appendingPathComponent(fileName)

if(contentUri?.path != nil) {
if let image = UIImage(contentsOfFile: contentUri!.path) {

if(mimeType.lowercased() == "image/png" ) {
if let imagepng = UIImagePNGRepresentation(image)
{
let imageData1: Data = imagepng
return imageData1
}
}
else if(mimeType.lowercased() == "image/jpg" ) {
if let imagepng = UIImageJPEGRepresentation(image, 1)
{
let imageData1: Data = imagepng
return imageData1
}
}
}
}

return nil
}

private func setupAndShow(activityItems: [Any], argsMap: NSDictionary) {
let activityViewController = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
let controller = UIApplication.shared.keyWindow!.rootViewController as! FlutterViewController
activityViewController.popoverPresentationController?.sourceView = controller.view
if(UIDevice.current.userInterfaceIdiom != .pad){
activityViewController.popoverPresentationController?.sourceView = controller.view
}
else {
if let popover = activityViewController.popoverPresentationController {
popover.sourceView = controller.view
let bounds = controller.view.bounds

if (UIDevice.current.userInterfaceIdiom == .pad) {
let originX:NSNumber = argsMap.value(forKey: "originX") as? NSNumber ?? NSNumber(value: Float(bounds.midX))
let originY:NSNumber = argsMap.value(forKey: "originY") as? NSNumber ?? NSNumber(value: Float(bounds.midY))
var originWidth:NSNumber = argsMap.value(forKey: "originWidth") as? NSNumber ?? 0
var originHeight:NSNumber = argsMap.value(forKey: "originHeight") as? NSNumber ?? 0

if (originWidth.intValue > (bounds.width - 96 as NSNumber).intValue) {
originWidth = NSNumber(value: Float((bounds.width - 96)))
}
if (originHeight.intValue > (bounds.height - 96 as NSNumber).intValue) {
originHeight = NSNumber(value: Float((bounds.height - 96)))
}

popover.sourceRect = CGRect(x:originX.doubleValue,
y:originY.doubleValue,
width:originWidth.doubleValue,
height:originHeight.doubleValue);
}
}
}

controller.show(activityViewController, sender: self)
}
}
}
Loading