receive_sharing_intent
receive_sharing_intent copied to clipboard
NSLog prints nothing to flutter debug console? Txt type files are not handled?
Txt type file (.txt, .text, .cvs) cannot be received on iOS, so I try to pring some marker in the swift file. However none of NSLog, os_log, print works. Any hints please.
i've fired in a PR to try and fix this issue (https://github.com/KasemJaffer/receive_sharing_intent/pull/137)
try adding this to your pubspec.yaml file...
receive_sharing_intent:
git:
url: https://github.com/LazyDave76/receive_sharing_intent.git
@LazyDave76 I try to receive a txt or csv file on Android phone with adding your git url. The result is not work.
Still not working.. Images -> getMediaStream : OK Text lines -> getTextStream: OK Text files -> getTextStream: Error type 'Null' is not a subtype of type 'String' in type cast
I'm running into a similar problem here. Trying to share a CSV file from another app to be received by my Flutter app, and the file that comes into the handler is always null. I've tried sharing other types of files from the same source app, and all of those work as expected. It looks like this plugin is interpreting a shared CSV file of type text/csv or text/plain as shared text, not a shared file?
If anyone else is looking at this issue, the fix in this PR seems to have worked for me:
https://github.com/KasemJaffer/receive_sharing_intent/pull/71
On ios, the cause of the problem lies in the judgment of the file type. The .text file may be a text text or a file at the same time. Therefore, you need to modify the viewDidAppear function of the ShareViewController.swift file in the ShareExtension, change the processing position of the following 2 lines of code, and process the file first, otherwise the .text file will be processed as text.
Below is the error code in the example:
else if attachment.hasItemConformingToTypeIdentifier(textContentType) {
handleText(content: content, attachment: attachment, index: index)
}
else if attachment.hasItemConformingToTypeIdentifier(fileURLType) {
handleFiles(content: content, attachment: attachment, index: index)
}
The following is the modified complete code:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.
if let content = extensionContext!.inputItems[0] as? NSExtensionItem {
if let contents = content.attachments {
for (index, attachment) in (contents).enumerated() {
if attachment.hasItemConformingToTypeIdentifier(imageContentType) {
handleImages(content: content, attachment: attachment, index: index)
} else if attachment.hasItemConformingToTypeIdentifier(fileURLType) { // Pay attention here
handleFiles(content: content, attachment: attachment, index: index) // Pay attention here
} else if attachment.hasItemConformingToTypeIdentifier(textContentType) { // Pay attention here
handleText(content: content, attachment: attachment, index: index) // Pay attention here
} else if attachment.hasItemConformingToTypeIdentifier(urlContentType) {
handleUrl(content: content, attachment: attachment, index: index)
} else if attachment.hasItemConformingToTypeIdentifier(videoContentType) {
handleVideos(content: content, attachment: attachment, index: index)
}
}
}
}
}
On ios, the cause of the problem lies in the judgment of the file type. The .text file may be a text text or a file at the same time. Therefore, you need to modify the viewDidAppear function of the ShareViewController.swift file in the ShareExtension, change the processing position of the following 2 lines of code, and process the file first, otherwise the .text file will be processed as text.
Below is the error code in the example:
else if attachment.hasItemConformingToTypeIdentifier(textContentType) { handleText(content: content, attachment: attachment, index: index) } else if attachment.hasItemConformingToTypeIdentifier(fileURLType) { handleFiles(content: content, attachment: attachment, index: index) }
The following is the modified complete code:
override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) // This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments. if let content = extensionContext!.inputItems[0] as? NSExtensionItem { if let contents = content.attachments { for (index, attachment) in (contents).enumerated() { if attachment.hasItemConformingToTypeIdentifier(imageContentType) { handleImages(content: content, attachment: attachment, index: index) } else if attachment.hasItemConformingToTypeIdentifier(fileURLType) { // Pay attention here handleFiles(content: content, attachment: attachment, index: index) // Pay attention here } else if attachment.hasItemConformingToTypeIdentifier(textContentType) { // Pay attention here handleText(content: content, attachment: attachment, index: index) // Pay attention here } else if attachment.hasItemConformingToTypeIdentifier(urlContentType) { handleUrl(content: content, attachment: attachment, index: index) } else if attachment.hasItemConformingToTypeIdentifier(videoContentType) { handleVideos(content: content, attachment: attachment, index: index) } } } } }
Thanks a ton! This works for me.