views:

693

answers:

1

We use encrypted web pages in our iPhone app, and intercepts these calls (e.g. when clicking a link) in the webView:shouldStartLoadWithRequest: method to get the file path, decrypt the data to the original html string and then doing a loadHTMLString: on the webView (returning YES in webView:shouldStartLoadWithRequest:, obviously).

The problem we currently have (after having taken other issues like having to implement our own back/forward state machine, taking care of scrolling to the last location, etc) is that it seems webView loads the images after it has called webViewDidFinishLoad:, which is where we're scrolling down to the #anchor if any (another thing we've had to implement as it doesn't work as it should when we use loadHTMLString: after decryption).

When we scroll down by using a javascript call ("window.scrollTo(0, document.getElementById('%@').offsetTop") it often ends up much farther up than it should; it looks exactly as if it calculated the .y distance before it loaded the images.

Is there a way to get back to the way the webView loads pages fully, and then scrolls to #anchors or the previous .y location?

This is a bit tricky to explain, and probably has some to do with intricate details in the way UIWebView loads, caches and presents pages. Some enlightenment and some clear thinking on this would be much appreciated.

A: 

I have used anchor tags with success, e.g.:

<a name='top'></a>
   ...
<a name='chap1'></a>
<a href='#top'>
   <h1>
      <img style='position:relative; top:2px; padding-right:5px;' src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAHVQTFRFAgICwMDAAwMDpKSk9/f3+/v7cHBwZmZmZGRkERER/v7+p6ensrKy0tLSXl5eVlZWaGhoW1tbYGBglpaWxsbGvb29sbGxY2NjcXFxVVVVwcHBtLS0bW1tWlpacnJyDw8P/f39GhoaCwsLAQEBycnJ////AAAA7TukbQAAAGxJREFUeNpkz+kSgjAMBODYVi6VG1FUrjR5/0dE1ME27M9vMrMbIBEg9rLBPQUPSkOBCxElR7r9oaVzbTX1+IOXuQ6PZtZjiB+A52nig+W4yuF7oRS/ARnBqV3B27GDToK9iOlZIcB5TmQRYAB6fSF0/d87AgAAAABJRU5ErkJggg==' alt='arrow-up.png' />
      Chapter 1
   </h1>
</a>...

Are your images encoded in Base64 and embedded directly within your freshly-unencrypted NSString*?

Alex Reynolds
They're unencrypted images.
avocade