I am writing an action extension to transform an image URL and copy to clipboard by clicking the share button of an image on a webpage in Safari.
I created an action extension in Xcode without UI.
In javascript preprocessing script action.js
, I can get the URL and title of the whole page.
run: function(arguments) {
arguments.completionFunction({
"URL" : document.URL,
"title": document.title
})
},
And that works for the share button of the whole webpage.
But how can I get the URL of the image that is pushed one?
2
Answers
Answering my own question. I had to create an action extension with User Interface so that I am working within
ActionViewController: UIViewController
class. The trick is to look forUTType.url.identifier
through the shared items.The code below works for share button of the whole webpage and an image.
When you use from URL, its better to use from :
this is better because of cache
you can Set your URL string with below code:
after that you can get URL with below code: