iosibooksios8-extension

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

<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

Mail, iMessages, Twitter etc. works as expected. Is there any additional magic i must do to handle this?


Solution

  • 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:

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