Reputation: 1474
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?
Upvotes: 3
Views: 630
Reputation: 36
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
}
})
}
}
}
Upvotes: 2
Reputation: 70936
The interesting things about this are
self.extensionContext.inputItems
is an empty array. It's not giving you anything to share.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.
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. But it doesn't look like you can get any content to share right now. I'd file a bug with Apple about it.
Upvotes: 4