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

Use data from configuration options in flutter #311

Open
koromkorom opened this issue Jul 3, 2024 · 0 comments
Open

Use data from configuration options in flutter #311

koromkorom opened this issue Jul 3, 2024 · 0 comments

Comments

@koromkorom
Copy link

Hi,

I only enabled text sharing and I simply want to add a title to the shared text. Here is my ShareViewController.swift. The UI part works. I can put a title and click on Post but the title is then not part of the value in ReceiveSharingIntent.instance.getMediaStream().listen((value). Can somebody please help me or provide a minimal working example of how something like this would work? Thank you!

import UIKit
import Social
import UniformTypeIdentifiers
import receive_sharing_intent

class ShareViewController: RSIShareViewController {
    var titleConfigurationItem: SLComposeSheetConfigurationItem?
    private var textString: String?
    private var titleItem: NSExtensionItem?

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func shouldAutoRedirect() -> Bool {
        return false
    }

    override func isContentValid() -> Bool {
        return true
    }

    override func didSelectPost() {
        super.didSelectPost()
    }

    override func configurationItems() -> [Any]! {
        if titleConfigurationItem == nil {
            titleConfigurationItem = SLComposeSheetConfigurationItem()
            titleConfigurationItem?.title = "Title"
            titleConfigurationItem?.tapHandler = { [unowned self] in
                let alertController = UIAlertController(title: "Title", message: nil, preferredStyle: .alert)
                alertController.addTextField { textField in
                    textField.placeholder = "Enter title"
                    textField.textAlignment = .center
                }
                
                // A cancel action
                let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { _ in
                    print("Canelled")
                }

                let confirmAction = UIAlertAction(title: "OK", style: .default) { _ in
                    if let text = alertController.textFields?.first?.text {
                        self.titleItem = NSExtensionItem()
                        if let titleItem = self.titleItem {
                            let itemProvider = NSItemProvider(item: text as NSSecureCoding, typeIdentifier: UTType.plainText.identifier)
                            titleItem.attachments = [itemProvider]
                        }
                    }
                }

                alertController.addAction(cancelAction)
                alertController.addAction(confirmAction)
                self.present(alertController, animated: true, completion: {
                    titleConfigurationItem?.value = alertController.textFields?.first?.text ?? "None"
                } )
                }
        }
        return [titleConfigurationItem!]
    }

} 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant