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.
In the Safari app , you can install extensions to customize the way your browser works. For example, extensions can help you find coupons when shopping, block content on websites, give you access to features from other apps, and more.
You can install Safari extensions to customize the way your browser works. For example, extensions can help you display social media and news buttons, block content on websites, give you access to features from other apps, and more.
View and add Safari extensionsGo to Settings > Safari, then tap Extensions. Tap More Extensions to browse through extensions in the App Store. When you find one you want, tap the price, or if the app is free, tap Get, then follow the onscreen instructions.
App Extensions are an iOS feature that allows developers to extend the functionality and content of their app beyond the app itself, making it available to users in other apps or in the main operating system.
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()
Source
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.
I think what you try to do is:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With