12

Why shouldStartLoadWithRequest not load my version / amp into the web view, and...

 2 years ago
source link: https://www.codesd.com/item/why-shouldstartloadwithrequest-not-load-my-version-amp-into-the-web-view-and-does-it-make-it-on-safari.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Why shouldStartLoadWithRequest not load my version / amp into the web view, and does it make it on safari?

advertisements

I have an iOS app with a UIWebView in it. In my webiste all my pages have an /amp version in it ( i.e www.website-example.com/pageX/amp )

In the shouldStartLoadWithRequest: method I do :url = [url URLByAppendingPathComponent:@"amp"]

if I do [[UIApplication sharedApplication] openURL:url];return false; (so it opens the url in Safari) it opens the good /amp version.

Otherwise, if I return false (after appending /amp), it opens the url in the webview, it doesn't open the /amp version, although the URL contains /amp.

edit: I'm adding Swift tag, because it's not a programming language problem, it's understanding shouldStartLoadWithRequest method.

What is the problem?


You can't append /amp to the url in shouldStartLoadWithRequest, /amp must be added and passed to the loadRequest method. It opens fine in safari because you are passing "good" url, but UIWebView is opening url before appending /amp, and in shouldStartLoadWithRequest you can't manipulate url.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK