Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSExtensionActivationRule & iOS App extension: how to activate the extension in iTunes

I want to make an extension for my iOS 8 app (preferably an action extension, but a share extension would do the job as well).
And I want this extension to be accessible from iTunes so my users could send an iTunes link to my app.
But I just can't figure out how to make this extension available from iTunes (and only from iTunes by the way).
I have tried NSExtensionActivationRule.NSExtensionActivationSupportsWebURLWithMaxCount, but it only activated my extension from Safari, not from iTunes.
I wonder if there could be a way to do it with a predicate, but I can't figure out how to build a predicate that can detect an iTunes "element/link" (for lack of a better term).
Does someone have a solution for that ?

like image 368
Frank Avatar asked Sep 04 '14 20:09

Frank


1 Answers

NSExtensionItem from AppStore/iTunes Store apps actually contain three types of attachment which are Image, Text and URL.

You can specify your NSExtensionActivationRule to TRUEPREDICATE first in development which allow all kinds of attachment.

The attachment structure of an AppStore/iTunes Store app extension request can be logged as image: enter image description here

As a result, you have to include following keys in NSExtensionActivationRule of your extension's info.plist file:

  1. NSExtensionActivationSupportsImageWithMaxCount
  2. NSExtensionActivationSupportsText
  3. NSExtensionActivationSupportsWebURLWithMaxCount

Update:

If you want to restrict the probably point showing your extension (which only work for iTunes Store), you could use "predicate statement" for more complex filter.

Please refer to the Apple doc below: https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW8

For example:

I want to make my extension only shows if the extension attachments meet the condition: one image, one plain text and one url, which confirms to the condition as image above. I use following prediction:

SUBQUERY (
    extensionItems,
    $extensionItem,
    SUBQUERY (
        $extensionItem.attachments,
        $attachment,
        ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image"
    ).@count == 1
).@count == 1
&&
SUBQUERY (
    extensionItems,
    $extensionItem,
    SUBQUERY (
        $extensionItem.attachments,
        $attachment,
        ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url"
    ).@count == 1
).@count == 1
&&
SUBQUERY (
    extensionItems,
    $extensionItem,
    SUBQUERY (
        $extensionItem.attachments,
        $attachment,
        ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.plain-text"
    ).@count == 1
).@count == 1

I didn't try to filter inside the attachment (only url contains "itunes.apple.com"), but I think you may use the prediction to restrict the point extension showing in action sheet and have more checking before taking action inside your view controller (not a perfect solution, but should work if there's no better way to check attachment content.)

Cheers!

like image 73
Charlie Hung Avatar answered Nov 18 '22 11:11

Charlie Hung