How to make UIWebView not act like a browser on the iPhone - iphone

My app loads webpages off the internet using a UIWebView. However I'd like to modify the experience so the user won't perceive it to be a webpage. What are some of the things I can do? and how to do it?
examples:
- Show the page when everything is loaded?
- Fade in effect?
Suggestions please.

It is possible to monitor the delegate callbacks from UIWebView to determine when the page has finished loading, and then perform whatever visual effect you want at that time. If the web view is most or all of your view controller, you could defer pushing your view controller until that time, or you could fade in the view as you mentioned.
However, even when reading HTML from the local disk, there is a noticeable lag. Waiting for remote content to load will have even more latency. You also must deal with the realities of an unreliable network: sometimes, your content will never arrive.
Once the first page is loaded and displayed, though, your options will be limited. If you try to make it appear that it is a fully native application, it's going to be hard to explain the latency or why it doesn't run when the network is unavailable (airplane mode, no cell or Wi-Fi).

I assume you are wanting to display the page as if it is a resource contained within your app (and not something streaming from a browser?)
In this case, download the webpage to a local file and display it only once fully downloaded.
I provide sample code in this answer that you can easilyy adapt for a html page (rather than a pdf document)

Related

May many webviews cause my app to crash on my iphone 4?

//The point
I gradually load many objects (UIWebView) to the memory and after a while it crashes. Please Help
//Details
I have a UIScrollView with horizontal paging, wherein each page (with a separate view controller) contains a UIWebView with disabled user interaction. At first only webview #0 on page 0 gets loaded and as I advance through the pages the app gradually sends requests to load specific data. Downloaded data stay in memory.
After I load about 20 Webviews from internet source, my app freezes and crashes. If I use a dummy html string stored on the device, this happens after I load about 50 webview. But the problem persists.
I fixed much of the leaks and am only left with Mallocs. Since the problem does not occur with low quantities of UIWebviews Loaded I assume that I have to change my code to say 3 webviews and reuse them. But I don't know if that'd fix the issue. I have developed several apps before which don't crash and this is a unique case.
I store pointers to webviews and some other elements inside every Webview (such as labels) in arrays. The arrays get incremented in count with every new page loaded.
I use xcode 4.3 and a jailbroken iphone 4 to develop. I turned off requiring signatures in my xcode as a result of which the app gets copied onto my phone yet fails to attach to process. I cannot debug on my phone. My app works well in simulator but crashes a while after I launch it on the phone by tapping the icon.
From what I am able to describe as so, what do you think might be the problem?
Thanks
Yes, certainly having too many UIWebViews will cause a crash due to low memory. I'm not sure what your reason is for having multiple UIWebViews, but I would follow through with your idea to reuse a smaller amount of them instead of creating several.
Based on your device not crashing when you use a small amount, I would say that the problem lies in the use of too many UIWebViews and not in a compatibility problem with your jailbroken device, for example.
WebKit is notorious for its memory hogging. It mallocs large blocks of memory and fails before giving you the opportunity to release other resources. One UIWebView is bad enough. I've had this problem in apps with as few a 5 UIWebViews, let alone 50.
There are a couple of things you can try. One, if the web pages aren't too complicated, you could use a replacement view such as DTCoreText to render them. If you have to have webviews, you could cache the various HTML contents and re-render using one UIWebView.
You only need to use three UIWebView's for paging. Lets say the user is on page 2 (page 1 is the left page and page 3 is to the right). When the uses swipes to page 3, you could just display the web view currently on page 1 on page 3. You need to re-load the proper html when the user swipes between the pages.
With some caching of the web content, speed shouldn't be a problem once the stuff is downloaded.

iOS app becomes unresponsive when html is being rendered in UIWebView

If I load request with large content in UIWebView, app becomes unresponsive after it finishes downloading content and starts rendering it. The loaded document also has some Java script content which will be executed on document load.
Also, app crashes if I minimize the app by pressing home button.
How to solve these issues?
Take a look at http://www.raywenderlich.com/4295/multithreading-and-grand-central-dispatch-on-ios-for-beginners-tutorial
In "Grand Central Dispatch in Practice" section describes your problem and a best-practice solution.
Best regards!

Retrieve data from API while launch image is shown

Is it possible to retrieve data from web service while launch image is being shown?
Or I will not show a launch image but I'll just use a view controller with an image (launch image), and retrieve data when that view controller is currently viewed?
You don't really have any control over the launch image, so the second option you listed is how you should do it.
Apple's Human Interface Guidelines suggests to "Start Instantly", not to use a launch image, but instead to show the actual interface as soon as possible, and if it's not ready yet, to show an activity indicator, etc.
The launch image is there simply because you application's delegate and main view controller are NOT yet loaded into memory. Par Apple documentation: launch images are there to look like the first view controller to give the perception that your application starts faster than it is truly is.
What this all means is that while the launch image is shown, you aren't getting anything but setup code done. The closet you could get loading something from the web on start up would be a "viewWillLoad" or "xxxWillLoad" type method. Loading an extra view controller is a waste of the user's time and (although considerably small) memory.

Is Instagram's Feed View based on UIWebView or UITableView?

It looks like UIWebView, but how do they implement that download progress bar and the section bar(very smooth scroll)...?
I have snooped around their logs, and I cannot guarantee that if the feed itself is a UIWebView, but it just so happened that when I went to the feed, a log message came up saying: "WebView loaded". This hints that they use a UIWebView for their feed.
I decided to do some research, and it seems I am not the only one who thinks that they might be using a UIWebView
http://www.lukew.com/ff/entry.asp?1499
If they are using a UIWebView, you should be able to easily identify its traffic in a proxy such as Charles or sniffing all network traffic using Wireshark.
After putting Instagram though Charles, I see that its calling http://instagram.com/api/v1/feed/popular/ which returns a set of JSON results. This leads me to believe it is definitely not a UIWebView and something created in native code (almost certainly a UITableView. As Andrew mentioned, the username UI elements behave exactly like UITableView section headers on a plain-style table.
I would say it is almost definitly a UITableView. Here's why I think this.
The profile picture of the poster is shown at the top while scrolling in the exact same manner that a UITableView shows section headers. (As I see you already noticed)
There is a slight delay when loading the next cell.
The scrolling is pretty smooth, but it would be smoother with continuous view (though it would take much more memory and the page would take longer to load).
What they probably do is pull information from the server and cache it in Core Data. They populate the table from this until you click refresh or close and open the app, at which point they reload the data and refresh the page. This includes comments, likes, descriptions and images.
The rest of it is choosing the right drawing methods to make the UITableViewCells as performant as possible. I won't go into this here, but there is a lot you can do to make the scrolling smooth.
#Neo
I've experienced the same gateway error as the screenshot from this article:
http://kennethormandy.com/journal/your-favourite-app-isnt-native
Safe to say their using UIWebView?
The way Instagram does this has been meticulously optimized, so what I'm about to say hardly scratches the surface of all of the methods they used to make their feed work.
They start by checking for a cache, and if one is not present, they call to server. Server returns the first meta of objects, which are cached/stored to disk.
Then they pre-allocate the height of the cell based on number & size of comments.
Now they setup their IB & UI methods, and everything (for the most part) executes normally.
The only other main thing is that they use pagination. So they're caching/saving to disk with each pagination.
Again, this is just the surface. There are a ton of hacks implemented into the feed in order to make it work so well. If you are planning to replicate this with a very similar model (content, comments, profile images, etc), it's going to take you some time to get it right.

Using the webView method, "loadRequest", do I need to worry about threading? (iphone sdk question)

Lets suppose I am creating an application for the iphone with a webView down at the bottom of the window (the other part of the screen has a button and the user can interact with it).
I don't want the webView to stop the user from interacting with the other part of the UI when the webView loads a new url. From my limited testing through the iphone simulator, I haven't been able to determine IF it already behaves this way. Most of my web sites load pretty fast.
I seem to be able to load new requests and click the ui button while that happens.
So, again, do I need to worry about threading in this case?
No, you do not. The iPhone threads a great deal of the UI components behavior, or schedules them for you in the main run loop in such a way that you rarely need to be concerned, the UI elements will be available for user interaction.