Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix share text on IPhone #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
43 changes: 19 additions & 24 deletions ios/Classes/SwiftEsysFlutterSharePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,29 @@ public class SwiftEsysFlutterSharePlugin: NSObject, FlutterPlugin {
self.files(arguments: call.arguments)
}
}


func shareItems(items: [Any], argsMap: NSDictionary) -> Void {
if(UIDevice.current.userInterfaceIdiom == .pad){
setupAndShow(activityItems: items, argsMap: argsMap)
} else {
// set up activity view controller
let activityViewController:UIActivityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil)

// present the view controller
let controller = UIApplication.shared.keyWindow!.rootViewController as! FlutterViewController
activityViewController.popoverPresentationController?.sourceView = controller.view
controller.show(activityViewController, sender: self)
}
}

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
setupAndShow(activityItems: [text], argsMap: argsMap)

shareItems(items: [text], argsMap: argsMap)
}

func file(arguments:Any?) -> Void {
Expand All @@ -49,18 +63,8 @@ public class SwiftEsysFlutterSharePlugin: NSObject, FlutterPlugin {
// add optional text
activityItems.append(text);
}
if(UIDevice.current.userInterfaceIdiom == .pad){
setupAndShow(activityItems: activityItems, argsMap: argsMap)
} else {
// 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)
}

shareItems(items: activityItems, argsMap: argsMap)
}

func files(arguments:Any?) -> Void {
Expand All @@ -84,17 +88,8 @@ public class SwiftEsysFlutterSharePlugin: NSObject, FlutterPlugin {
// add optional text
activityItems.append(text);
}
if(UIDevice.current.userInterfaceIdiom == .pad){
setupAndShow(activityItems: activityItems, argsMap: argsMap)
} else {
// 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)
}
shareItems(items: activityItems, argsMap: argsMap)
}

private func setupAndShow(activityItems: [Any], argsMap: NSDictionary) {
Expand Down