2

I've got the following from this tutorial on creating a ShareExtension:

override func didSelectPost() {
        self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
}

Which uses this javascript to get the url:

var GetURL = function() {};
GetURL.prototype = {
   run: function(arguments) {
      arguments.completionFunction({"URL": document.URL});
   }
};
var ExtensionPreprocessingJS = new GetURL;

I'd like to understand how I can modify the the didSelectPost so I can pass this URL to my main app. I've created a shared app group from this response, but the problem is my main app uses Firebase to store and update the TableView (which is just a list of URLs, like a reading list). I understand I can't use Firebase in the shareExtension (they are meant to be as simple as possible) - but I can't figure out a way of doing it otherwise.

Any help would be greatly appreciated!

Community
  • 1
  • 1
Dominic
  • 33
  • 4

1 Answers1

-3

Create a variable: var url: URL? on the top of your ShareViewController. Then, add this code in the viewDidLoad to set the value of your url:

viewDidLoad Code

You can then try to access the url variable in your didSelectPost area through a guard statement: guard let successfulURL = self.url else { return }, and use the successfulURL variable however you would like to. Hope this helped.

Max Khan
  • 21
  • 10