【问题标题】:iOS share extension in chromechrome中的iOS共享扩展
【发布时间】:2015-05-05 11:46:35
【问题描述】:

刚刚向我的应用添加了共享扩展。 它在 safari 中运行良好。 从 Chrome 启动它时,不会调用“ExtensionPreprocessingJS.js”。 因此没有调用以下代码:

MyExtensionJavaScriptClass.prototype = {
run: function(arguments) {
    // Pass the baseURI of the webpage to the extension.
    arguments.completionFunction({"baseURI": document.baseURI});
},

请指教。

【问题讨论】:

    标签: google-chrome safari ios8-share-extension


    【解决方案1】:

    这种行为被记录为 Safari 选项,而不是适用于每个网络浏览器。

    在共享扩展(在两个平台上)和操作扩展(仅限 iOS)中,您可以要求 Safari 运行 JavaScript 文件并将结果返回给扩展,从而授予用户访问 Web 内容的权限。

    [强调我的]

    【讨论】:

    • 谢谢汤姆,我知道了。我的问题是有人能想到使用 chrome 的解决方法吗?显然这是可能的,因为某些应用确实支持 chrome 共享扩展。
    【解决方案2】:

    尝试将其放入/替换/添加到您的 info.plist 扩展中

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

    【讨论】:

      【解决方案3】:

      不需要那些复杂的东西。这适用于 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
                          }
                      })
                  }
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-10-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多