Reputation: 493
The application i'm working on requires me to launch the application from any webpage so it can rip the text from that webpage via stringByEvaluatingJavascriptFromString (which requires the url).
How do you launch an application from mobile safari from any webpage?
In addition would it be possible to access the url of the current webpage from the app whilst doing this?
The current method i'm using requires one to copy/paste the url directly into the app.
From what I've seen so far it can be done via bookmarks but i'm not sure about how the code would work.
Upvotes: 3
Views: 3295
Reputation: 454
You can register your app to a custom URL scheme (See: How to register an app to respond to a custom URL scheme opening request?). When a URL with this scheme is opened in Mobile Safari, your app delegates application:didFinishLaunchingWithOptions: method will be called. The URL will be passed in the options dictionary as UIApplicationLaunchOptionsURLKey.
Now you can create a bookmark in Mobile Safari, which opens your app and passes the URL along:
javascript:window.location="yourAppURLScheme://?url="+window.location
Upvotes: 4