receive_sharing_intent icon indicating copy to clipboard operation
receive_sharing_intent copied to clipboard

NSLog prints nothing to flutter debug console? Txt type files are not handled?

Open beelabcloud opened this issue 4 years ago • 7 comments

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.

beelabcloud avatar Feb 06 '21 03:02 beelabcloud

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 avatar Feb 25 '21 20:02 LazyDave76

@LazyDave76 I try to receive a txt or csv file on Android phone with adding your git url. The result is not work.

shawn736 avatar Apr 04 '21 15:04 shawn736

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

marcio-ota avatar Apr 26 '21 16:04 marcio-ota

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?

ntmcminn avatar May 19 '21 17:05 ntmcminn

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

ntmcminn avatar May 27 '21 01:05 ntmcminn

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)
                    }
                }
            }
        }
    }

tangzijun avatar Oct 22 '21 09:10 tangzijun

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.

AdarshAPT avatar Dec 07 '21 13:12 AdarshAPT