我正在处理Share Extension
这是info.plist文件的代码。这在Safari中运行良好,但不适用于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>
有什么想法吗?如何在Chrome中启用共享扩展程序
答案 0 :(得分:7)
您缺少一些代码。对于chrome,您还需要传递js文件
<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>
了解更多详情请访问此link
中的演示扩展程序代码答案 1 :(得分:1)
就我而言,只添加带有“ NSExtensionJavaScriptPreprocessingFile ”的JS文件并没有解决问题。
<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>
添加以下内容也很重要:
<key>NSExtensionActivationSupportsText</key>
<true/>
我目前不知道为什么。
我在官方文档中找到了这个: NSExtensionActivationSupportsText :包含此密钥以向系统和其他应用指示您的应用支持文字。
非常感谢。
答案 2 :(得分:0)
只有safari使用此数组 NSItemProvider = [[NSExtensionItem attachments] firstObject]; 其他浏览器使用API NSItemProvider = [[NSExtensionItem attachments] objectAtIndex:1];
答案 3 :(得分:-1)
无需编辑plist。这适用于Google Chrome和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
}
})
}
}
}
}