3

当向我的应用程序的共享表发送一个链接 ( NSURL) 时,我收到一个单曲NSExtensionItem,其中不仅包含带有内部的附件,而且还具有共享表中NSURL输入的文本的有效属性。( )attributedTitle

但是 - 当我使用我的共享表共享图像时,即使我在我的共享表中输入了文本,NSExtensionItem(其中只有一个attributedTitle)对于or没有任何值attributedContentText

从照片发布图像

如果我打印出NSExtensionItem,我只会看到:

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

这与我通过完全相同的机制共享 URL 时看到的情况形成了鲜明对比:

通过 Safari 共享表发布 URL

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

注意 key 的值NSExtensionItemAttributedContentTextKey

为什么输入的文本丢失,我可以做些什么来确保它进入共享表?

4

1 回答 1

3

事实证明,访问附件的attributedTitleorattributedContentText属性并不是解决问题的方法,即使它可能适用于 URL 类型。

相反,self.contentText使用SLComposeServiceViewController

于 2015-07-12T13:29:37.753 回答