Can a web app in UIWebView gain access to native storage - ipad

If I have a web app running in a UIWebView can the javascript context in the web app get any sort of access to data in the native ipad app context? I'd like to store lots of images in the native app database, then access these from a web app running in a UIWebView within the native app.

Not directly, but if you can get some kind of "bridge" working with Javascript, you can use native code to pass back paths to files and such. Look into the the stringByEvaluatingJavaScriptFromString:#"SomeJSCommandHere". Check out this webpage for more information on that. It looks like they discuss it.

Related

Titanium WebView - Is there a way to stop it opening a system app?

I'm working on a very simple app at the moment that has a tabgroup which open's up various webviews containing different URLs.
One of the webviews is a google maps link, on the device I am using it has the Google Maps App installed. Instead of opening the link in the google maps website, it opens up the link in the App instead. If I test the app in a simulator without the google maps app installed, the webview will load the website version instead.
Is there a way to stop the device from using the system app and force it to use the website instead? So far I have been unable to find any information.
Thanks.
I'm kind of surprised that the WebView is doing what you're describing. I would expect it to directly load the contents of the URL you've provided, regardless of whether another app is registered for that URL scheme. But I'll take your word for it.
I have two ideas on this:
could you use ti.map instead of a google maps URL? I'm not sure what your map contains; this may not be practical for you
could you use HTTPClient to retrieve the HTML from the google maps URL, and then call WebView.setHtml() with that HTML? I would imagine you might have to add a element to the HTML to get all the relative URLs in the page to work...

How do I prevent Mobile Safari from accessing the network for a cached webapp?

I have a simple web app that I want to use locally (i.e. I don't want it to ever access the network). All the code is packaged according to the Safari Web Content Guide. I was successful in downloading my web app to my iPhone. I noticed, though, that even though my web app doesn't connect to anything remotely, there will be a network access (the network access indicator fires).
I suspect that iOS is checking to see if the web app is fresh (i.e. checking the cache manifest to see if it needs to update any files). Is there a way to prevent this? It really screws up the user experience.
The never-ending network spinner is a bug in iOS; you won't be able to get around it with a web app:
http://www.devthought.com/2012/09/22/understanding-the-ios6-ajax-bugs/

PhoneGap/Cordova and external url instead of www/index.html

I'm about to build and app with Cordova.js to enable file upload on the iPhone. I'd like to just use the regular responsive web site and include the cordova.js to get access to native features like the camera.
I read somewhere that Apple might reject apps that loads external urls in an app like this. Is this true and what's the real problem?
Would it be different if the app contains a local page by default and opens external content on user interaction?
Well if you app can be reproduced by a web site then Apple will just reject it. You are going to add camera features so that is a good start. If you don't use some native features they will reject it out of hand.
Secondly Apple does not like apps that load code from remote locations. They want to be able to go over everything themselves and don't like the idea of things changing without them being able to verify it first. So, remote data is okay but remote code is not in their eyes.

How does the Facebook app for iPhone work?

I will soon be writing a native iPhone app for my web site. The web site is already mobile optimised so could potentially just sit in a UIWebView. How does the Facebook app work? Does it do something similar?
If I did use a UIWebView then how would I store user credentials so they don't have to log in every time and how would they upload photos? These are my two main requirements.
The facebook app is going to be a native app. It is different from the mobile website.
There are two things you can do here. If you're going to make your native app just a UIWebView then don't bother! You can have an apple icon embedded in your website which will show if a user bookmarks your website on their home screen. To use this use the <link rel="apple-itouch-icon" href="/apple-touch-icon.png" /> code to do it.
The second is make a fully native app. I know the benefits of a UIWebView app, but the negatives are plain to see. UIWebView apps are tacky, nonfunctional and terrible to use. A mobile website is not an app (unless done very well). You will have links to click, pinch and zoom, awful bounce effects on the web view, links that may possibly allow users to navigate away from your mobile website but within your app. Again, unless done cleverly, you will have to provide browser controls on your app which will make it look like a tacky web browser.
My suggestion would be either stick with your website, optimise it for touch based input, make it a really good mobile website, or create a fully functional native application. Remember not all websites need to have an app to go with it. If your app isn't necessary then its merely counter productive to make an app for it. I don't know about anyone else, but I spend more time in my web browser than I do in apps.
With regards to uploading and auth then a) auth should be done already in your website. A UIWebView is just an instance of safari working within your app, so it will be able to get and store cookies and all sorts. I believe these degrade at the end of the app session, however its easy to pass to the objective c and store in an stored preference. b) uploads not going to work even if you put your site in a web view. You will have to (at some point) hand off to an upload screen in your app which is running natively.
I would suggest that you start off with a simple native app. Let the users log in, upload stuff and do other basic stuff - whatever they can't currently do on your mobile website. Then move on to other things as people ask for them, or as you have the time to make them. You don't have to launch your app with a fully functioning version of you website (in fact this would be silly because the only thing they cannot do on your mobile website on their phone is upload stuff). I'm sure people will request features as your product evolves.
I would take a look at PhoneGap, you can get access to native device features through javascript http://phonegap.com/

Force URL to open in a Web Clip if installed?

Let's say I have a web app that calls out to a native app via a custom URL scheme, and after the native app has done its thing it returns to my web app by opening a callback URL.
This all works fine when my web app is running in Safari. But what happens if a user saves the web app to the home screen (creating a "Web Clip")? In that case it runs in a separate process from regular safari, and has separate cookies and cache.
So when the native app tries to return to the web app, the URL will presumably get opened by Safari, not by the Web Clip, and the session will be lost. (And not just the session -- all the page state, which in a rich Javascript-based web app can be a lot of stuff with non-trivial startup time.)
Is this assumption correct? And if so, is there any way around it? Is there some way to get iOS to try to open the URL with a web clip if installed?
In order to have something launch via a custom url scheme on iOS, you must have an application register this information via the Info.plist built into the app.
It is not possible to have a webapp/webclip register this information system-level.
So, to answer your main question, you cannot do this.
Here is the information on implementing custom URL schemes in native applications.

Resources