How to Launch an iOS native app from the current native app
In Objective C I can write like
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"SomeApp"]]
How can I achieve the same in JavaScript?
var window = UIATarget.localTarget().frontMostApp().mainWindow();
Above code uses UIATarget,Is it possible to access the UI elements of the new app as it was launched from another app. I think it might not be possible,but I would like to use it for testing and I don't want to use Jail breaking.
If that can be done in JavaScript, Could somebody provide pointers on this ?
In Android, using some frameworks we can access the UI elements of any Application.
Is it feasible in iOS ?
URL Schemes are the only way to communicate between apps.
Communicating Between Apps
When using Instruments/cmd line UI testing (Tune_up.js) you cannot communicate with apps outside of the target testing app. When your app leaves the foreground you won't be able to get it back except for one case.
UIATarget.deactivateAppForDuration();
This will behave as though the user has hit the home button, and after the duration goes to the multi-tasking board and brings your app back to the foreground.
Related
I'm trying to detect all installed apps on an iPhone from Safari.I have a list of 3000 URls scheme.From a WebView and using javascript, I want to loop this list and save the excitant apps (URls scheme that have a response) .Is that possible?
Simply not possible, as #rckoenes said, it would launch each app you call - therefore halting your browser instance - and looping through that many URIs even if it did return a value rather than launching the app would probably make you no friends. there are ways and means of detecting if YOUR app or AN app is present and launching it via smart meta banners or look at this project: https://github.com/hampusohlsson/browser-deeplink
I build a webapp and I have social links in my webapp.
I am facing an issue regarding this. If I am having facebook installed in my device then on click of the share link it should open the native app instead of opening in browser.
And incase if I doesnt have any native app installed then it should automatically redirect to browser.
Here it is the code what I have tried:
Javascript:
if(isAndroid){
fb://profile//www.facebook.com/sharer/sharer.php // to open in native browser
http://wwww.facebook.com // to open in web browser.
}
How do I handle this urls...
Please help me out.
This is not possible, for privacy reasons.
See This answer
You can make Hybrid Application.
What you just need to do is ADD WEB INTERFACE which will make call to native source code through javascript and also get return value.
So you can write native function which will return if application is installed. Once you set this interface you can use it further for open that app and passing intent and all that.
You can do it easily. Start Here:
https://developer.android.com/guide/webapps/webview.html
I have a webpage that is being viewed from a webview in a native app, this webpage has a element. The file input works fine in the web browser but does not work in the app (different problems on both iPhone and Android).
The app has already been published and I would really not like to update the native portion of the app.
The ideal solution would be to add java-script to the webpage that can detect that it is running inside the app and then launch a browser (outside of the app) with the URL.
Is this possible somehow?
It's possible if your app overrides default user agent used by webview. By default the user agent for webview is same as that of default browser. So you don't have any way to differentiate those. If your app overrides useragent, then you can sniff useragent using javascript & take action based on that. Ideal solution will be to try to fix the problem with your html though.
My understanding is that it's impossible to launch the browser which is outside of the app without changing the app.
You may add a code like below in iOS.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString *address = request.URL.absoluteString;
if( address is needed to be launched on the webbrowser ) {
[[UIApplication sharedApplication] openURL:request.URL];
return NO;
}
return YES;
}
It's recommanded to define a protocol between the webpage and the app. Cheers.
Launching a browser should be no problem, as posted here:
Can I launch an intent using only javascript in an Android browser?
However, detecting the app is tough. If you are already using a javascript bridge in the app, then you can make a call to the native app javascript bridge and if it succeeds, then you know you are in "your app" and can respond with the intent call above.
Failing that, user agent detection, as mentioned elsewhere, may be your best option.
In other words, you need an identifiable and unique action within the webview in order to have confidence that you are actually in it. If you did a plain vanilla implementation, then you will be forced into either having user interaction ("If you are using our app, click here" - horrible!) or updating the native app.
Instagram has some cool hooks that can be used to open the app from a web url.
e.g. instagram://camera
But when a user doesn't have instagram installed, the browser doesn't know how to handle the url. Is there a way for me to detect if the user has instagram installed (in javascript)?
In Objective-C the [[UIApplication sharedApplication] canOpenURL:url] expression may be used to detect whether a URL is handled by any app in the system. If you use PhoneGap or some similar framework, then look for this method. If you have only a webapp, then I'm pretty sure that this is impossible.
The issue with a web app is that it is sandboxed like a web page, it cannot reach outside of the browser. However, it seems to be possible that you can detect the presence with a timing based method. That is, if the app is not installed, the user will return to, or not be able to leave at all the browser within a certain, relatively short time. Thinking along these lines I found this solution: Check if URL scheme is supported in javascript
You may be able to build a solution using this approach, but the "Cannot Open Page" alert box will always be thrown at your users. Though, this IMHO is not really annoying if you handle it correctly on the web app side.
UIApplication has a method canOpenURL: that you can use to check.
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"instagram://camera"]]) {
}
I want to build 1 UI for several phones (windows phone, Android, IPhone, etc).
My plan is to create an HTML5 UI, and use JS to invoke applications that are installed on the mobile device.
For example, I create windows phone 7 application without UI, and invoke functions of this application from the JS in the HTML 5 UI.
Same goes for android, IPhone, etc.
Is this plan feasible at all?
- How can I call windows phone 7 silverlight app/Android from JS?
Calling a native app from the browser is
possible on iOS: Opening Native App. from Safari
possible on Android: Launch custom android application from android browser
impossible on Windows Phone 7
On iOS, you can't create a web app that calls native code, period. You mention that you want the app to have no UI, so I'm assuming you want to have a web app that invokes native code which in turn causes something to happen in the web app, or even causes something to happen on the device. Won't happen. You can use the iPhone's Custom URL Scheme to LAUNCH an application with given parameters so that when it opens it immediately does something, but you will get kicked out of the browser and in to your app. And App Store Guidelines wouldn't let you make an app that has no UI. It also doesn't allow for the creation of apps that are just WebViews wrapped around HTML.
On Android, I would imagine that you could create an app that is nothing more than a WebView that loads your webapp, and in that way you would have access to the native code you wrote for the device, but I don't think that would meet up in the middle the way you want it to when it comes to having the native code manipulate your web app. Plus Android UI's are mostly XML with a little bit of backing code so at that point you may as well be making a native app.
The browser in Windows Phone 7 does not currently support HTML5, though it is expected to arrive later this year. That said, I would extremely surprised if there was ever a public API that enabled a web site to open an application on the host device and I'd be surprised if this was allowed on Android or iPhone, too.
The only application that I'm aware of that exhibits this behavior is the YouTube application. If you visit YouTube.com on the WP7 browser, then it either launches the YouTube app if you have it installed, or prompts yout to download and install it. So, the capability is there, but I doubt very strongly if Microsoft would ever open it up beyond a close partnership for specific applications.
In Windows Phone 7, you can use the WebBrowser control within an application to host/browse web content, and from the application you can call javascript methods exposed by that page as described by Shawn Wildermuth in his Navigating with the WebBrowser Control on WP7 post.