3

When sending a link (NSURL) to my application's share sheet, I receive a single NSExtensionItem that contains not only the attachment with the NSURL inside, but also has a valid property for the text entered in the share sheet. (attributedTitle)

However - when I share an image using my share sheet, even if I have typed text into my share sheet, the NSExtensionItem (of which there is only one) does not have any values for the attributedTitle or attributedContentText:

Posting image from Photos

If I print out the NSExtensionItem, I only see:

<NSExtensionItem: 0x6100000030b0> - userInfo: {
    NSExtensionItemAttachmentsKey =     (
        "<NSItemProvider: 0x61000004a110> {types = (\n    \"public.jpeg\"\n)}"
    );
}

This contrasts what I see when sharing a URL via the exact same mechanism:

Posting URL via Safari Share Sheet

<NSExtensionItem: 0x600000007620> - userInfo: {
    NSExtensionItemAttachmentsKey =     (
        "<NSItemProvider: 0x600000245b20> {types = (\n    \"public.url\"\n)}"
    );
    NSExtensionItemAttributedContentTextKey = <7b5c7274 66315c61 6e73695c 616e7369 63706731 3235320a 7b5c666f 6e747462 6c5c6630 5c667377 6973735c 66636861 72736574 30204865 6c766574 6963613b 7d0a7b5c 636f6c6f 7274626c 3b5c7265 64323535 5c677265 656e3235 355c626c 75653235 353b7d0a 5c706172 645c7478 3536305c 74783131 32305c74 78313638 305c7478 32323430 5c747832 3830305c 74783333 36305c74 78333932 305c7478 34343830 5c747835 3034305c 74783536 30305c74 78363136 305c7478 36373230 5c706172 6469726e 61747572 616c5c70 61727469 67687465 6e666163 746f7230 0a0a5c66 305c6673 3234205c 63663020 4170706c 657d>;
    supportsJavaScript = 1;
}

Note the value for key NSExtensionItemAttributedContentTextKey.

Why is the entered text missing, and what can I do to ensure that it makes it to the share sheet?

Craig Otis
  • 31,257
  • 32
  • 136
  • 234

1 Answers1

3

Turns out accessing the attributedTitle or attributedContentText properties of the attachments is not the way to go about it, even though it might work for URL types.

Instead, use the self.contentText of the SLComposeServiceViewController

Craig Otis
  • 31,257
  • 32
  • 136
  • 234