Is it possible to use an iOS 8 Action Extension to send a selected text from the Safari browser to an installed app? I'm thinking about this workfow: The user would select a text in a website >taps the share icon >the installed app (not only the share dialog) opens with the selected text.
3 Answers
You need to turn on NSExtensionActivationSupportsWebURLWithMaxCount to make extension available in Safari.
When you create a non-UI action extension target from the template, an Action.js file is automatically created. Edit the file to send back the selected text using
document.getSelection().toString()

- 15,898
- 3
- 42
- 75
As all extensions are running on iPhone as with the main app. You can use something like App Group to share the information.
So you need to enable the App Group capability in both targets and share information with UserDefault(suiteName:) or use shared container file directory(with shared container you may need file coordinator to make 2 process will not use the file the same time).
What's more, if both processes are running, you can use darwin notification to notify the other one there is new information updated.

- 480
- 2
- 11
I think what you try to do is:
- Select text on website
- Click Share button on toolbar at the bottom of Safari
- Open your app with the selected text attached to some userInfo dictionary
Unfortunately, I think that is not possible. You can create a extension to accept the selected text but it won't open your app completely rather than just the extension.
The problem is that there is no "Open in..." selection when marking text in Safari (compared to for example the "Open in..." if you select a file in lets say the Dropbox app).
As far as I understand the functionality (and to be honest, I have not digged to far into it so I might be wrong), when you click the share menu in Safari (may it be the one from the black popup bubble when selecting the text or the one from the bottom toolbar button), it will fire an "one time" extension which lets you execute a particular action (like sending the selection via messages, email or put it in your notes). After the extension has been executed, it will return to where it was fired (meaning safari).
Again, thats different to the "Open in..." for which you would need to implement custom url schemes for your app to listen for. But that does not work with simple text selection. It would need a real url scheme.
Maybe this question helps you to get a better understanding: iOS Share vs Action App Extension
To sum up: What you are trying is most likely not possible on iOS.
Possible idea: You could somehow try to add a button to the sharing extension which generates a custom url scheme with the selected text and asks the system to open the url but I can imagine that this won't really work

- 6,175
- 2
- 31
- 50
-
fantastic answer, plus one, should be winner – developer_hatch Jun 01 '17 at 18:27
-
Zoom App does that. If you have zoom installed in your iphone you can select any text > tap share > select zoom > and zoom app is opened – Matheus Lima Jan 14 '21 at 15:55