So I am creating a web browser for iPhone for my class and I am having an issue where whenever I submit a form-like thing from a website, it doesn't update my address bar text (which is a UITextfield). As an example, if I go to google.com on my browser and so a search for something in the search field and hit submit, it loads a new page without changing my address bar (it's still on google.com). I have it to change for links, but I don't see how to make it so it works for forms like this. I added a NSLog in my webViewDidFinishLoading function and it doesn't say the page is loading, so I'm not sure how to detect when it changes this way. Does anyone have any ideas why it's not working?
Intercept it in this method instead:
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType;
The navigationType can be UIWebViewNavigationTypeLinkClicked , UIWebViewNavigationTypeFormSubmitted or others. And [request URL] will be an NSURL object with the page URL about to be loaded.
Related
I really want to thank you all you guys first , I began iOS programming learning several weeks ago ,and I have learnt a lot from here these days,.
I have a UIWebView and loading some html content with "loadHTMLString" method, when i click hyperlinks in the UIwebView, It comforms the
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType{
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
[[UIApplication sharedApplication] openURL:[Request URL]];
return NO;
}
return YES;
}
to open a Safari.
My question is: Can I go back from the Safari to the UIWebView? how?
You can't get Safari to send the user back whenever you want, but one way to get back to your application is by creating a custom URL scheme (e.g. myapp://return, or whatever scheme makes sense to you), assuming that the web page the person is going to can have links that are intended to go back to your appliaction.
You can do this by registering that your application handles the URL scheme, and then processing the request appropriately when iOS tells you to. The Apple docs are fairly complete about this.
But if you want your application to be able to arbitrarily pull people back whenever you want, I don't think that's possible. Safari isn't under the control of anyone but Apple.
I'm currently developing an iPhone app for a mall.
One of the features is the ability to phone a mall tenant from within the app. I'm using
NSURL *url = [[NSURL alloc] initWithString:#"tel:1(480)555-5555"];
[[UIApplication sharedApplication] openURL:url];
It works as I expect it to, no confirmation dialog and remains in the phone app when the call is completed. I'd rather it return to our app, but whatever...
However, there is another page in the app that is a webview and there are a couple of phone numbers that have been automatically detected. Upon clicking one, the confirmation dialog box opens, and the user is returned to our app.
I'm a little ticked that the behaviour that I want, and was seemingly removed between 3.0 and 3.1, exists in a webview. Ideally, I'd like any phone number to return a user to our app, but I'm okay with neither of them doing it. I just want it to be consistent throughout my app.
Is there a different call I should be using? Can I change the behaviour of phone numbers that have been automatically detected in a webview? (besides disabling it)
Unfortunately, this is not simple to do. The UIWebViewDelegate callback - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType should allow you to intercept these taps but it does not. (Note: in the simulator it does appear to work, but on device it doesn't...) My guess is that the only way to intercept these taps would be at the window level and that would probably be more work than it is worth.
We have a wifi hotspot that displays a terms of service page before people are allowed to start using it.
After acceptance, a new page with a few links is displayed. I'd like to have those links open in Safari instead of in UIWebView.
I know there's a way to program UIWebView to open links in Safari, but that's not an option as this is the default UIWebView for logging into wifi hotspots and not a custom app.
Is there another way to have the links open in Safari and not in UIWebView? I've tried javascript and I've tried setting the target to _blank.
EDIT: After reading some responses, it seems like the only way to do this is to set the UIWebView delegate. I don't think this is an option because I'm not the one launching the UIWebView.
When the iPhone connects to the network (at least with version 3.0), it checks to see if it's being redirected to a login page. If it is, it does what you're saying with authentication and such inside of a UIWebView. Have you checked to see what it's reporting as the browser in use? If it isn't Mobile Safari, then you could do something server-side the first time someone connects using Mobile Safari.
If it does report as Mobile Safari when it's checking redirection, then another alternative is to figure out what site it tries to go to - maybe apple.com? Then, on the server side, the first time a different URL is loaded, redirect to your links. This will only work when the user opens Mobile Safari, however.
Other than that, I think what you're asking to do is outside of the scope of the current iPhone OS. I'd recommend filing a ‘feature request’ with Apple at bugreport.apple.com.
The only way I know how to do this is to set up a UIWebView delegate and supply something like the following:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
if (navigationType == UIWebViewNavigationTypeLinkClicked &&
[request.URL isFileURL] == false)
{
[[UIApplication sharedApplication] openURL:request.URL];
return NO;
}
return YES;
}
The code above will cause Safari to open a link clicked on by the user. I know you said you had little control over this UIWebView -- perhaps you have more than you think by setting the delegate?
Use the openURL method of UIApplication:
NSURL *url = [[NSURL alloc] initWithString:#"http://example.com"];
[[UIApplication sharedApplication] openURL:url];
[url release];
An Apple example of this is available as part of the LaunchMe sample.
I am creating a dictionary lookup application. The user selects a word from a UITableView and the app displays the definition. In some cases the word will be similar to another word, so I want to display "See Also:" followed by a list of similar words that when touched, bring up another definition.
In searching here on links within UITextViews, most of the answers involve linking out to the web, which is not really what I need. I simply want to get control when the user touches a word so that I can change the view.
Is UIWebView the only way to do this, or did I miss something obvious in the SDK? Also, I'd prefer to stay within the native SDK and not go the three20 route.
Thanks!
I would use another UITableView to make this work. Your list of similar words will probably be in NSArray format already, so it would be pretty easy to set up another UITableView instead of a UITextView to display the list, and given that you already have this code working for the main UITableView, you already know how to make them clickable!
A UIWebView will be the only thing that suits here I'm afraid. Data detectors are the only way to link inside of a UITextView, and they will only respond to the appropriate data types (Phone number, web page, address)...
Links can be done the normal way:
<a href='http://someotherword'>someotherword</a>
Setup the webviewdelegate to snag any link requests (and prevent them from being opened in the browser) so that you can open them in your own handler:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
{
if(navigationType == UIWebViewNavigationTypeOther) return YES; // Allow direct loading
NSString *myWord = [[request URL] host];
// do something with myWord... say open another word
return NO; // Don't let the browser actually perform this navigation
}
Ok so in mobile safari you can pull up a web page and touch and hold on an image to save it to the iPhone's photo library. In a UIWebview on a view this does not happen (it pops up the alt-text and never prompts you). I'm wondering if anyone knows a way to turn this feature on.
One way to do it (on tap) would be to
grab the content
Do smart img tag finding to find all img tags
find / replace with a link to some arbitrary place http://foo.com?REAL_IMG_SRC
overload - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType in your delegate
intercept all links that contain foo.com
Use the REAL_IMG_SRC to download/present save options/etc...