简体   繁体   English

iOS 8共享扩展程序不适用于iBooks

[英]iOS 8 share extension doesn't work with iBooks

I try to share selected/highlighted text in iBooks with my custom extension, but it doen't have anything inside self.extensionContext 我尝试使用我的自定义扩展程序在iBooks中共享选定/突出显示的文本,但它在self.extensionContext中没有任何self.extensionContext

<NSExtensionContext: 0x17541d90> - UUID: <__NSConcreteUUID 0x1765e860> D69F0393-C5F1-4DEB-9A97-B479C2BC0C95 - _isHost: NO
items:
(
)

so after i choose my extension in provided list it just pops up empty SLComposeServiceViewController 所以在我在提供的列表中选择我的扩展后,它只会弹出空的SLComposeServiceViewController

Mail, iMessages, Twitter etc. works as expected. Mail,iMessages,Twitter等按预期工作。 Is there any additional magic i must do to handle this? 我必须做些额外的魔术才能解决这个问题吗?

The interesting things about this are 有趣的是这个

  • When sharing from iBooks, self.extensionContext.inputItems is an empty array. 从iBooks共享时, self.extensionContext.inputItems是一个空数组。 It's not giving you anything to share. 它没有给你任何东西可以分享。
  • Sharing from iBooks only works normally with extensions that were provided by Apple. 从iBooks共享仅适用于Apple提供的扩展。 On my iPhone other extensions are available from iBooks-- Evernote, Things, and others-- but none of them work normally. 在我的iPhone上,可以从iBooks获得其他扩展 - Evernote,Things和其他 - 但它们都不能正常工作。 They all come up with empty content. 他们都提出了空洞的内容。

My take: Sharing from Apple's extensions relies on some undocumented secret behavior, and there's no extra magic you can apply that would get through the app store approval process. 我的看法:Apple的扩展分享依赖于一些无证的秘密行为,并且没有额外的魔法可以通过应用程序商店审批流程申请。

If you set your activation rule to TRUEPREDICATE (which means that the extension should always show up) or something very lenient, your extension will show up in iBooks. 如果您将激活规则设置为TRUEPREDICATE (这意味着扩展程序应始终显示)或非常宽松,您的扩展程序将显示在iBooks中。 But it doesn't look like you can get any content to share right now. 但看起来您现在无法分享任何内容。 I'd file a bug with Apple about it. 我向Apple提交了一个关于它的错误。

It does seem like that the issue has been resolved with iOS 9, the following code (in Swift) correctly returns the contents of the selection in iBooks: 似乎问题已经通过iOS 9解决了,下面的代码(在Swift中)正确地返回了iBooks中选择的内容:

for item: AnyObject in self.extensionContext!.inputItems {
        let inputItem = item as! NSExtensionItem
        for provider: AnyObject in inputItem.attachments! {
            let itemProvider = provider as! NSItemProvider
            if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeText as String) {
                itemProvider.loadItemForTypeIdentifier(kUTTypeText as String, options: nil, completionHandler: { (txt, error) in
                    NSOperationQueue.mainQueue().addOperationWithBlock {
                            //Doing stuff with txt
                    }
                })
            }
        }   
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM