分享扩展在Chrome中无法工作

6

我正在开发分享扩展。

这是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中启用分享扩展?

1
只是为了增加一些价值,这里提供两个相关的参考链接。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
4个回答

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>

要了解更多详情,请访问此链接以查看演示扩展代码。


这对我不起作用。请帮助我解决。 - Madhumitha
你遇到了什么问题,请解释一下。 - Hitu Bansal
1
我测试了Chrome浏览器,它没有执行Javascript预处理器,而Safari浏览器却可以。 - dickyj
仅适用于Safari浏览器。 - Denis
1
它对我不起作用,甚至Safari浏览器也不起作用,但我可以获取URL。请建议我做错了什么。 - Mss iOS
这个答案绝对不正确 - Chrome 不会执行 NSExtensionJavaScriptPreprocessingFile,只有 Safari 会。 - Austin

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:包含此键以指示系统和其他应用程序您的应用程序支持文本。

非常感谢。


0

只有Safari使用这个数组 NSItemProvider = [[NSExtensionItem attachments] firstObject]; 其他浏览器使用API NSItemProvider = [[NSExtensionItem attachments] objectAtIndex:1];


-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
                    }
                })
            }
        }
    }
}

这正是我在寻找的。不明白为什么这个答案会有两个踩。点赞并感谢你。 - Thanh-Nhon Nguyen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接