IOS Share extension: how to read from notes posts

2019-02-22 07:01发布

问题:

I want my app to be able to parse text from notes app post as well other text editors posts, so i created an share extension target. Everything worked fine until i prepare the app for publish, replacing the TRUEPREDICATE by NSExtensionActivationRule.

Supposedly, in my share extension target, i should add NSExtensionActivationSupportsText key to NSExtensionActivationRule in info.plist, which i did, but still my app extension doesn't show up in the share sheet.

According to https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html my info.plist should contain this:

<key>NSExtensionAttributes</key>
<dict>
   <key>NSExtensionActivationRule</key>
   <dict> 
        <key>NSExtensionActivationSupportsText</key>
        <integer>1</integer>
   </dict>
</dict>

I try enable also other types like attachments, files, web pages, but had no effect.

回答1:

At least in iOS 9, the correct code is

<dict>
    <key>NSExtensionActivationSupportsText</key>
    <true/>
</dict>

For reference, this is typically what it would like for text share extension support:

<key>NSExtensionAttributes</key>
<dict>
    <key>NSExtensionActivationUsesStrictMatching</key>
    <integer>2</integer>
    <key>NSExtensionActivationRule</key>
    <dict>
        <key>NSExtensionActivationDictionaryVersion</key>
        <integer>2</integer>
        <key>NSExtensionActivationSupportsText</key>
        <true/>
    </dict>
</dict>