Can you please help me in the matter of supporting apple news sharing ,
My Share Extension info.plist contains :
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsAttachmentsWithMaxCount</key>
<integer>10</integer>
<key>NSExtensionActivationSupportsText</key>
<true/>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsWebPageWithMaxCount</key>
<integer>10</integer>
</dict>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
</dict>
How can i see my share extension while share some thing from apple news ?
OK I sorted this out. You need to configure your Extension to allow content for both public.plain-text
and public.url
types. Apple News sends an ItemProvider with two attachments, first a plain-text piece with the article summary, and second a Web URL to the article itself. You must accept and process both.
Try these extension attributes. They use a predicate to find the required URL type attachment (assuming that's what you want):
<key>NSExtensionActivationDictionaryVersion</key>
<integer>2</integer>
<key>NSExtensionActivationUsesStrictMatching</key>
<integer>2</integer>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<string>SUBQUERY(extensionItems, $e, (
SUBQUERY($e.attachments, $a, ANY $a.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url").@count == 1
)).@count == 1
</string>
<key>RequestsOpenAccess</key>
<true/>
</dict>
And code along these lines to find the proper URL attachment, again, assuming that's the bit you want:
NSExtensionItem *inputItem = self.extensionContext.inputItems.firstObject;
NSItemProvider *itemProvider;
for (itemProvider in [inputItem.userInfo valueForKey:NSExtensionItemAttachmentsKey]) {
if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *) kUTTypeURL]) {
break;
}
}
if (!itemProvider) {
// Handle error here
return;
}
[itemProvider loadItemForTypeIdentifier:(NSString *) kUTTypeURL options:nil completionHandler:^(NSURL *url, NSError *error) {
// Handle the URL here
}];