Cordova: sharing browser URL to my iOS app (Clipper ios share extension)

前端 未结 5 2000
南笙
南笙 2020-11-30 01:20

What I want

On an Iphone, when visiting a website inside Safari or Chrome, it is possible to share content to other apps. In this case, you can see

5条回答
  •  一生所求
    2020-11-30 02:13

    Following up on the iOS 10 update remark by Aaron Rosen, here's the process to make it work :

    1. In the code from the original answer by Sebastien Lorber, update the doOpenUrl function as suggested by Aaron. Reposting here for clarity:

      private func doOpenUrl(url: String) {
      let url = NSURL(string:url)
      let context = NSExtensionContext()
      context.open(url! as URL, completionHandler: nil)
      var responder = self as UIResponder?
      while (responder != nil){
          if responder?.responds(to: Selector("openURL:")) == true{
              responder?.perform(Selector("openURL:"), with: url)
          }
          responder = responder!.next
      }
      }
      
    2. Follow the process outlined in the initial answer to create the extension in Xcode

    3. Select ShareViewController.swift in the extension folder
    4. Go to Edit > Convert > To Current Swift Syntax
    5. In the extension build settings, toggle "Require Only App-Extension-Safe API" to NO.

    Only then will the extension work.

提交回复
热议问题