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

extractData fix for image data #4

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
12 changes: 8 additions & 4 deletions ios/Modules/ShareMenuReactView.swift
Original file line number Diff line number Diff line change
@@ -126,7 +126,7 @@ public class ShareMenuReactView: NSObject {
semaphore.wait()
} else if provider.hasItemConformingToTypeIdentifier(kUTTypeImage as String) {
provider.loadItem(forTypeIdentifier: kUTTypeImage as String, options: nil) { (item, error) in
let imageUrl: URL! = item as? URL
var imageUrl: URL! = item as? URL

if (imageUrl != nil) {
if let imageData = try? Data(contentsOf: imageUrl) {
@@ -139,15 +139,19 @@ public class ShareMenuReactView: NSObject {
let imageData: Data! = image.pngData();

// Creating temporary URL for image data (UIImage)
guard let imageURL = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("TemporaryScreenshot.png") else {
let tmpDir = NSTemporaryDirectory()
let tmpFilename = NSUUID().uuidString + ".jpg"
imageUrl = NSURL.fileURL(withPathComponents: [tmpDir, tmpFilename])

if imageUrl == nil {
return
}

do {
// Writing the image to the URL
try imageData.write(to: imageURL)
try imageData.write(to: imageUrl)

results.append([DATA_KEY: imageUrl.absoluteString, MIME_TYPE_KEY: imageURL.extractMimeType()])
results.append([DATA_KEY: imageUrl.absoluteString, MIME_TYPE_KEY: imageUrl.extractMimeType()])
} catch {
callback(nil, NSException(name: NSExceptionName(rawValue: "Error"), reason:"Can't load image", userInfo:nil))
}