iOS 5 bug: UIWebView and goBack and goForward - objective-c

I found a bug in iOS 5.
When you are using a UIWebView and access some sites, you create your history links, look like any other browser.
If you like to use a navegation bar, can use the functions goBack and goForward
In iOS 4.3 and below, when you call this function the program call the delegate function
webView:shouldStartLoadWithRequest:navigationType:
But in iOS 5.0 this can happens or not. If the site is in cache, it not call this function. I saw this happens in only 1 level (1 click in goBack or 1 to goFoward), in the second click it pass in the function.
Why they change it???? Even it is in cache, the program have to ask for me.. Now how solve this: I am trying make a stack with the browser history and I check the url. But i am having problem ;(
There are no other way?
I can't see the browser history? I have to create my ow list?
I can't clean the cache to force it pass in the function?
Any sugest?

It's not a bug, if there is enough available RAM on the device then it will keep some of the pages in memory, therefore they are not being "loaded" again when you go back.
You should create your own goBack: and goForward: actions on your own controller, and link the goBack/goForward buttons to them:
- (IBAction)goBack:(id)sender
{
[self doStuff];
[self.webView goBack:sender];
}

Related

Handling WebView having loaded?

I'm writing a browser application for Mac to match my Windows one. I have a WebView on my window and so far I have a working browser. However, I need to run a method I've written when the WebView finishes loading a page. Is there a way to do this? If not, how can I work around that? Thanks!
You can call your method in the webView:didFinishLoadForFrame: delegate call that is in the WebFrameLoadDelegate.

Titanium - Reset zoom scale in webview

Is it possible to programmatically reset the zoom/scale that the user has done in a webview? My issue is when the webview is pinch zoomed in landscape and you rotate the phone, the webview is still zoomed in and in my case, portrait mode is now extremely zoomed in.
I've tried webview.repaint() but that seems to do absolutely nothing. I know I can call webiew.reload() but that just uses more bandwidth for my server as well as the users data plan so I want to avoid that.
I'm using Titanium Studio, build: 3.1.3.xxx, 3.1.3 GA Ti SDK and compiling for iOS 7 SDK.
Based on this thread and the fact that there was no way to easily achieve this, I have created a module. It extends the Ti.UI.WebView with two methods, setZoomLevel() and scrollToTop(). It is very basic at the moment, but I'm planning on extending its functionality gradually.
https://github.com/mwfire/titanium-module-extended-webview
Have a look, it's an alternative to modifying the core code.
Did you give a try at setting the scalesPageToFit property of your webview upon orientation change?
http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.UI.WebView-property-scalesPageToFit
I found the answer which was a bit more than I wanted to do. I had to actually modify the Titanium SDK obj-c files.
I modified 3 files:
TiUIWebView.h
-(void)resetZoomScale; //-- added this line to define the function in the header file
TiUIWebView.m
//-- Added this function that will actually handle the resize
- (void)resetZoomScale
{
[webview.scrollView setZoomScale:1.0]; //-- reset the scroll view back to 1
}
TiUIWebViewProxy.m
//-- Call the resetZoomScale function in TiUIWebView.m file
//-- I believe this also exposes the function to javascript
-(void)resetZoomScale:()args
{
TiThreadPerformOnMainThread(^{[(TiUIWebView*)[self view] resetZoomScale];}, NO);
}
I can now call myWebView.resetZoomScale(); and whatever pinch/zooming has been done on the web view will be reset back none or 1

After exiting app, how to go back to the exact same screen where I left off?

Is there a quick and easy way to have the app go back to the same screen after I put it in background mode?
I know there are frameworks just for this stuff, but has anyone done it without much sweat?
Thanks
In your app delegate, add a line to the applicationDidenterBackground: method that stores the current page via NSUserDefaults.
Then in the applicationWillEnterForeground: method, load up that saved value and restore the page.
Multitasking should enable this, while a device has enough memory to keep your app open. Otherwise how about using NSUserDefaults to store a string reference to your view?
As of iOS 5.1, there is no quick and easy way.

iOS App - Refresh last webView on applicationDidBecomeActive

I have a single view iOS app, that contains a webView that displays my website. When the app is returned to from multitasking (when it is brought back as the active app) I would like the webView to get the URL it is currently on, and refresh (or reload) that current page in the webView (I'm thinking using this method):
- (void)applicationDidBecomeActive:(UIApplication *)application
{
NSLog(#"applicationDidBecomeActive");
}
How would I do this? Do I need to subscribe to some sort of notification? Please help point me in the right direction, and provide some code.
There are some point to get noticed are like:
Application should allow user to run in background mode. You can define this in info.plist
Implement UIWebViewDelegate in your view controller. There is one method: webViewDidStartLoad:
Inside that method get the current url
NSString *currentURL = [webView stringByEvaluatingJavaScriptFromString:#"window.location"];
(For more details refer this.)
Save this url string to some where, and while relaunching your application the method which you mentioned in the question gets called. Inside that method, load your web view with this url string.
Hope this is what you required.
Enjoy coding :)

What method gets called before a WebView is closed by owner window?

I'm working with a webview within a window of a Cocoa application. I would like to retrieve some values using stringByEvaluatingJavaScriptFromString on the webview and save them before the application shuts down. I tried using the applicationWillTerminate but by the time I reach this method, it is too late. I was wondering if there's something built into webview that I've missed or if anyone has an elegant solution to share.
If you want to save this information, why are you waiting until the app is about to terminate?