iosswiftcocoa-touchios8-extensionios8-share-extension

How to make an iOS 8 share extension that will have default text


In my app there is text displayed in a label on screen.

I have a share button when pressed brings the UIActivityViewController but when you press the share extensions ex: Twitter, you get the compose view with nothing inside of it.

I want it that it puts the text from the label on the screen into the compose view.


Solution

  • I don't know how you did this but it would work well. suppose you put it on a action sheet :

    let share = UIAlertAction(title: "Share my label!", style: .Default, handler: { action in
            let shareMessage = myLabel.text
            let itemsToShare = [shareMessage]
    
            let activityViewController = UIActivityViewController(activityItems: itemsToShare,
                applicationActivities: nil)
    
            self.presentViewController(activityViewController, animated: true, completion: nil)
    
        })