-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
addded paste method channel in native ios folder (#462)
- Loading branch information
1 parent
df46f31
commit b678da1
Showing
1 changed file
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,42 @@ | ||
import UIKit | ||
import Flutter | ||
import UIKit | ||
|
||
@main | ||
@objc class AppDelegate: FlutterAppDelegate { | ||
override func application( | ||
_ application: UIApplication, | ||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? | ||
) -> Bool { | ||
// Register the method channel | ||
let controller = window?.rootViewController as! FlutterViewController | ||
let clipboardImageChannel = FlutterMethodChannel(name: "clipboard_image_channel", | ||
binaryMessenger: controller.binaryMessenger) | ||
|
||
clipboardImageChannel.setMethodCallHandler { (call: FlutterMethodCall, result: @escaping FlutterResult) in | ||
if call.method == "getClipboardImage" { | ||
self.getClipboardImage(result: result) | ||
} else { | ||
result(FlutterMethodNotImplemented) | ||
} | ||
} | ||
|
||
GeneratedPluginRegistrant.register(with: self) | ||
return super.application(application, didFinishLaunchingWithOptions: launchOptions) | ||
} | ||
} | ||
|
||
private func getClipboardImage(result: FlutterResult) { | ||
// Check if the clipboard contains an image | ||
if let image = UIPasteboard.general.image { | ||
// Convert the image to PNG data | ||
if let imageData = image.pngData() { | ||
// Encode the image data to a Base64 string | ||
let base64String = imageData.base64EncodedString() | ||
result(base64String) // Send the Base64 string back to Flutter | ||
} else { | ||
result(FlutterError(code: "NO_IMAGE", message: "Could not convert image to data", details: nil)) | ||
} | ||
} else { | ||
result(FlutterError(code: "NO_IMAGE", message: "Clipboard does not contain an image", details: nil)) | ||
} | ||
} | ||
} |