6

I am working on Share Extension

Here is code of info.plist file . this is working fine in Safari, But not in Chrome.

 <key>NSExtension</key>
        <dict>
        <key>NSExtensionAttributes</key>
        <dict>
            <key>NSExtensionActivationRule</key>
            <dict>
                <key>NSExtensionActivationSupportsImageWithMaxCount</key>
                <integer>0</integer>
                <key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
                <integer>1</integer>
            </dict>
        </dict> 


        <key>NSExtensionMainStoryboard</key>
        <string>MainInterface</string>
        <key>NSExtensionPointIdentifier</key>
        <string>com.apple.share-services</string>
    </dict>

Any idea? how to enable share extension in Chrome as well

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
arun kamboj
  • 1,145
  • 4
  • 17
  • 48
  • 1
    Just to add some value, two references about this. http://www.pixeldock.com/blog/how-to-show-your-ios-share-extension-only-in-safari-or-other-browsers/ https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/SystemExtensionKeys.html#//apple_ref/doc/uid/TP40014212-SW10 – Adriano Tadao Jan 19 '16 at 16:10

4 Answers4

7

You are missing some code . For chrome you need to pass js file as well

<dict>
        <key>NSExtensionAttributes</key>
        <dict>
            <key>NSExtensionActivationRule</key>
            <dict>
                <key>NSExtensionActivationSupportsText</key>
                <true/>
                <key>NSExtensionActivationSupportsWebPageWithMaxCount</key>
                <integer>1</integer>
                <key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
                <integer>1</integer>
            </dict>
            <key>NSExtensionJavaScriptPreprocessingFile</key>
            <string>DemoPreprocessor</string>
        </dict>
        <key>NSExtensionMainStoryboard</key>
        <string>MainInterface</string>
        <key>NSExtensionPointIdentifier</key>
        <string>com.apple.share-services</string>
    </dict>

for more detials Please visit demo extension code from this link

Hitu Bansal
  • 2,917
  • 10
  • 52
  • 87
1

in my case, only adding the JS file with "NSExtensionJavaScriptPreprocessingFile" did not solve the problem.

<key>NSExtension</key>
    <dict>
            <key>NSExtensionAttributes</key>
            <dict>
                    <key>NSExtensionJavaScriptPreprocessingFile</key>
                    <string>Action</string>
                    <key>NSExtensionActivationRule</key>
                    <dict>
                            <key>NSExtensionActivationSupportsText</key>
                            <true/>
                            <key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
                            <integer>1</integer>
                    </dict>
            </dict>
            <key>NSExtensionMainStoryboard</key>
            <string>MainInterface</string>
            <key>NSExtensionPointIdentifier</key>
            <string>com.apple.share-services</string>
    </dict>

It's also essential to add the :

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

I currently don't know why.

I've found this in the official documentation : NSExtensionActivationSupportsText : Include this key to indicate to the system and to other apps that your app supports text.

Thanks a lot.

Amélie Medem
  • 141
  • 2
  • 5
0

only safari use this array NSItemProvider = [[NSExtensionItem attachments] firstObject]; other browser use the API NSItemProvider = [[NSExtensionItem attachments] objectAtIndex:1];

吊 Man
  • 1
  • 2
-1

No need to edit plist. This works both in Google Chrome and Safari:

override func viewDidLoad() {
    super.viewDidLoad()

    for item in extensionContext!.inputItems {
        if let attachments = item.attachments {
            for itemProvider in attachments! {
                itemProvider.loadItemForTypeIdentifier("public.url", options: nil, completionHandler: { (object, error) -> Void in
                    if object != nil {
                        println(object) //This is your URL
                    }
                })
            }
        }
    }
}
Esqarrouth
  • 38,543
  • 21
  • 161
  • 168