Share extension does not work in Chrome

I am working on the Share extension

Here is the info.plist file code. this works 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 sharing extension in Chrome as well

+5
source share
4 answers

You are missing the code. For chrome, you also need to transfer the js file

 <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 details. Please visit the demo code from.

+7
source

in my case, just adding a 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 is also necessary to add:

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

Currently, I do not know why.

I found this in the official documentation: NSExtensionActivationSupportsText . Enable this key to indicate to the system and other applications supported by your application.

Thank you very much.

+1
source

only safaris use this array NSItemProvider = [[Attachments NSExtensionItem] firstObject]; another browser uses the API NSItemProvider = [[Attachments NSExtensionItem] objectAtIndex: 1];

0
source

No need to edit plist. This works in both 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 } }) } } } } 
-1
source

All Articles