UIWebView opens safari on load - objective-c

I have a UIWebView in my application. If I tell it to open the url #"http://twitter.com/" it open in that same webView fine. But if I ask it to open a url like (similar to the one I need it to open): #"feed://www.OcataCore.com/rss/news.xml" it opens up safari as soon as the view that contains the UIWebview is loaded. Is there a way i can force that url to be opened in my webview ?

UIWebView does not offer the same range of features as Safari does. Except html, UIWebView is capable to read the formats listed in this Q&A. It appears like it is not capable of displaying XML, no matter if it is taken from a feed or a local file.

agreed, should not be able to open XML files.
hope this helps though if you are just wondering how to open Safari. use this delegate method of UIWebView to open the links.
webView:shouldStartLoadWithRequest:navigationType
that should work.

Related

Any way to stop UIWebView from opening pdf automatically

Is there a way to stop UIWebView from opening PDF files automatically?
Html file that gets loaded is not local and it holds links (href) to some pdf files. Now I would like those files to be downloaded to some local folder on the device instead of being opened by UIWebView by default when the user touches the link buttons.
Is there any way to do this at all? Oh, and if possible without html/xml parsing since I still want to use UIWebView for browsing other pages?
The reason why I don't want UIWebView to open pdf files is because I want my own custom view to do that instead.
Implement the webView:shouldStartLoadWithRequest:navigationType: delegate method for your web view. Check the navigationType for UIWebViewNavigationTypeLinkClicked to see if it is a link tapped by the user. Check the URL of the request to see if it is for a PDF file.
If it matches these criteria, then return NO from the delegate and do your own processing to download and display the PDF file.

How to open a document in other specific app - like Safari does it with iBooks when viewing a PDF - without using UIDocumentInteractionController?

If you view a PDF in Safari, it will show button in the toolbar that reads "Open in iBooks".
As far as I know there is the custom URL scheme "itms-books:" for iBooks and that allows passing a file path. iBooks then seems to be able to copy the file from the source app (from anywhere, or only from the personal documents folder?).
How does this work? The only way I'm aware of to share documents with other apps is via UIDocumentInteractionController, but that that is tied to the default popup.
Is there a way to transfer files using a custom URL scheme like iBooks does?
Or is this some hack only Apple is allowed to use (private API)?
Another way I could think of is to render the controller off screen, loop through it and touch the correct target app by code. Sounds dirty though....
Please note that my intention is not to open something in iBooks but in another app somebody else implemented (that app would be registered for the file types I offer and maybe have a custom URL scheme if required).

UIWebView disable location prompt

Is it possible to disable the location prompt (or auto decline/accept it) that pops up when you visit certain websites that ask for locations? I am not using a MKMapView because my app will be not be just viewing maps (it just may visit websites that might have maps on it).
I'm guessing since the prompt is not being controlled by my app, but by the iOS system, I probably will not be able to auto decline/accept the dialog.
As far as disabling the prompt from within an IOS app while loading a UIWebView, it is possible.
You will need to intercept the html before it gets loaded into the UIWebView then find which part of it triggers the GPS/Location Prompt. Once you found it, you simply remove it from the html then feed the html into the UIWebView thus 'disabling' the prompt. However, as a result, the webpage will be missing that element.
No, it's not possible to do that. Not with UIWebView, not with any iOS browser.
I know no way to prevent the prompt, I hope it will be implemented as a property of the UIWebView.
The dialog is not there for the safety of the user, when it comes to UIWebViews. The app containing the view has already asked for locations access, and it can be enabled and disabled on settings. To ask for location access both from the app and from the web view, I would regard as a bug.

How can I download files from UIWebView using ASIHTTPRequest?

I want to create a section of my app where you can download the current webpage showing in the UIWebView and then save it to a UITableView and when you tap on the filename in the UITableView, it will load the local file in the UIWebView to allow offline browsing.
How can I do this with http://allseeing-i.com/ASIHTTPRequest? I've taken a look and all the code looks very daunting for a beginner! Is there an alternative method? Is this the best method?
Thank you
ASIWebPageRequest is the answer. It's a class included with ASIHTTPRequest that makes it easy to download whole pages, with all their associated dependencies.
You'd probably want to create a custom cache to store your downloaded webpages in, and then load them out of that cache when requested by the user.

iphone app UIWebView cache data

I need a UIWebView to show a html page. if internet is not available it will show the last downloaded version. if has internet then it downloads the most current version and replaces and shows the version just downloaded. how can I do this? Thanks
You could implement you webViews delegate webViewDidFinishLoad: method to grab the request and load it again. Since it was just finished loading, we can assume that it is cached and load it with synchronous networking. Store the result. When network is unavailable load that result into the webView using loadData:MIMEType:textEncodingName:baseURL:. When network comes available agin just call loadRequest: to refresh.
Another option is to use stringByEvaluatingJavaScriptFromString: with a javascript around:
document.getElementsByTagName('html')[0].outerHTML;
and inserting the content with loadHTMLString:baseURL:
But these two only work for pure HTML without images, sounds, etc.
A third option would be to use the NSURLRequestReturnCacheDataDontLoad when network is not available. see NSURLRequest
You migth also have a look at the NSURLCache