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.
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
Related
I have an android app working this way:
User read QR-code with my specific URL
If the app installed it intercepts this URL and handles it somehow.
If app not installed standard browser opens this URL and it leads to Google play on app page.
When user install and run app first time it read browser's history and look for my URL.
If app found URL in browser's history then it handles this URL again.
Is it possible to implement this behavior on iPhone/iPad?
I suppose key features here are to read browser history and to intercept http URL's.
If this is impossible how would you implement this thing on iOS?
Thanks in advance for your help.
You can use custom application URLs in the form: myApp://... iOS will automatically launch the application if present. The logic for handling the 'not-installed' case has to be in the QR code scanning app. can be handled by the scanned website via a forwarding link using the iOS custom URL scheme (this might be useful for usage stats).
Additional info on implementing Custom URLs...
I want to launch my application from the url received to user via an sms.
How do I achieve it?
The format of my url is:
https://companyname.net/productname/?some_parameters_for_user
I want to prompt user to open url in safari or my app and depending on his choice, the app will be launched either in safari or directly the native app.
The url opens in safari but how to invoke native app? and take user to a particular page in app?
Please help.
Thanks in advance.
Look at the custom URL scheme. It's described in several places. Here is a link to "Advanced App Tricks"
It's described there, along with many other helpful ideas.
Question:
I am actively looking in the source code on Github's facebook-ios-sdk project myself but I was wondering if anyone already knows how to relaunch an app that sent an iPhone user to Safari, such that the user can come back after some work has been finished?
Example:
When using facebook to login, the original app is relaunched after the facebook login page has authenticated the user.
Motivation:
I would like to be able to do the same for youtube videos without having to completely lose the user. I don't want to use the standard webview approach because I don't want to provide extra space to first let the video load for the user and then have the user click the play button. I want to skip the play button and its associated click entirely! Instead I want the user to be able to click on just an everyday regular iPhone button and be shown the video with the navigation for coming back to the app via relaunch.
You need your app to register a "custom URL scheme". Then get the callback in the remote web service to return a URL with that scheme. iOS will then launch your application.
More (somewhat old) info available here.
A list of common custom URL schems on iOS can be found here.
Generally, as part of the OAuth login process, you supply a callback URL as one of the paramaters. What this does, is tell the remote server (YouTube), that on successful authentication, redirect the user to the supplied URL. If YouTube supports this (does it support OAuth?) then on successful user login within safari, youtube will tell users safari to redirect to the supplied url. If this url is a "custom URL scheme" it will cause your app to relaunch and you can handle the situation from there.
I'm building a full-screen iPhone optimized web app. It gets launched from the homepage like a native app and behaves like a standalone app via the following directive, but it's just plain HTML/CSS/JavaScript, no PhoneGap involved.
<meta name="apple-mobile web-app-capable" content="yes" />
When trying to authenticate over OAuth, the redirect to Twitter (or any other OAuth provider) takes me out of my full-screen web app and into Mobile Safari. Once the Twitter auth completes, the redirect back to my app does not launch my homepage app, instead just redirects within Mobile Safari. Is it possible to do OAuth inside an iPhone homepage web app? Short of that, can I get the OAuth callback to re-launch my homepage web app?
I've had a similar problem recently, and found that if you set the URL in Javascript with a window.location.href="http://example.com/whatever" then iOS doesn't switch to Safari. I've managed to get PayPal checkout and Facebook login working in standalone web apps without switching to safari using this method! If you're submitting a form, do that via JS too and get the redirect URL from the response then set the location. As for handing back to your app afterwards, it depends on how the external service works.
If that's no good, you could do a pop-up alert('You will be passed to Safari for authentication. Reload this app afterwards.') before they get switched to Safari. Not great, but better than surprising them with automatically switching apps!
I´m assuming that you have a "manifest" meta tag to reference manifest.json file.
I suggest you to do the following workaround. It works perfect on ios safari web app:
https://stackoverflow.com/a/52286655/8390589
I was wondering if anyone knows - if I have an iPhone app that is registered with a URL service (e.g. alocola://), which means another app can invoke it by calling its URL - is there any way to embed this URL in an HTML page, and catch the exception if the app is not installed on the user's iPhone?
Or in other words / more details:
I would like to write an app that conforms to some URL invocation (like alocola:// is doing), but would like this app to be launched from a web page read by mobile Safari. However, if the app is not installed on the user's iphone, I would like to be able to display a note saying "you must have the alocola app installed on your iPhone, please download it from the app store by clicking here". Is there a way (perhaps using javascript) to have Safari indicate that the URL cannot be invoked, and catch this in order to display an intelligent message?
Thanks :-)
Ariel
No, there's no way to detect this and display such a message. Instead, you should put text on the webpage saying that the using the link requires your app.