This is really annoying me. I have a webView, and I am trying to get it too load drive.google.com. However, because of the amount of redirects on that site, the webView does nothing. I know that the code for loading a webView works, and that URL is correct, as I get the didFailWithProvisionalLoadWithError message. That is how I know that it is the redirect problem.
I have looked all over, but can find no way to alter the amount of allowed redirects. I know that it is possible, as Safari can handle it. There has to be some kind of delegate method to override. No code today, as all my searches (4 days worth of them) have lead me to nothing.
If anyone has an idea, let me know. FYI, this is Cocoa (WebView) not cocoa touch (UIWebView). Thanks.
That for which you have been searching is
– webView:decidePolicyForNavigationAction:request:frame:decisionListener:which is part of the
WebPolicyDelegateprotocol.Read the documentation for
WebPolicyDelegate, particularly the discussion for this delegate method. The documentation forWebPolicyDecisionListenerdescribes the messages you can send to the listener. You might identify a redirect inside this delegate method, and you could instruct the decision listener to use or ignore it.EDIT:
I appreciate the 50 points, but if I didn’t help you solve your problem, I hardly think I deserve them, and that was enough guilt to motivate me to sit down and try out your problem.
I built a tiny app, one that isn’t document based, or uses ARC or garbage collection. I turned off Auto Layout in the MainMenu.xib file, and simply placed an instance of WebView inside it. I modified AppDelegate to include an outlet for the WebView instance.
I then created fleshed out the
-applicationDidFinishLaunching:stub like this:and if I’m getting redirects, they don’t seem to be affecting my ability to display the page.
Are we on the same page (no pun intended)?
EDIT 2:
Good news (or bad news, depending on your POV): Redirects were never the problem (though they did help to shed light on what was really going on).
When it comes to Google Drive, WebView isn’t an approved browser. You can, however, fix that (N.B., below) by modifying the user agent string. Here’s the revised code:
N.B.: The user interface appears to be fully functional, but even so, Google may change its means of determining what the browser is and break this scheme, so consider yourself warned. You might want to explore their SDK for possible alternate means of accessing Google Drive.
As always, good luck to you in your endeavors.