I upgraded DropBox framework in my app and now I have to use linkFromController.
There is a way to detect if user tap on cancel button or if the DropBox auth popup is visible or not?
Thanks,
Max
You can use Following delegate to filter the loading url. Find url that load in cancel button and use it to complete your task.
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *url = [[request URL] absoluteString];
if([url isEqualToString:#"Cancel Url"]){
//Do what you want
return NO;
}
}
Related
How can I detect when a UIWebView changes a page? At the minute I am using
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
but this not only detects the page change but also each request on the page.
I am trying to get it so that when the user clicks on a link it detects the click and then I can see what the url is that the user is trying to see.
Any ideas?
Thanks
So, you could interrogate navigationType ... defined as ...
enum {
UIWebViewNavigationTypeLinkClicked,
UIWebViewNavigationTypeFormSubmitted,
UIWebViewNavigationTypeBackForward,
UIWebViewNavigationTypeReload,
UIWebViewNavigationTypeFormResubmitted,
UIWebViewNavigationTypeOther
};
typedef NSUInteger UIWebViewNavigationType;
... and act accordingly, and/or look into the request for any particulars ...
NSURL *url = [request URL]; or NSURL *url = [[request URL] absoluteString];
I have UIWebview in my app and this is how i navigate some times in the application to URL:
NSURL *url = [NSURL URLWithString:#"http://mp3skull.com/mp3/nirvana.html"];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
And sometimes i noticed that if i click on link the AppStore application is opened with some app.
It is possible to disable it?
In the method - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
You could do
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString *requestedURL = [[request URL] absoluteString];
// URL for opening itunes according to Apple docs is something like this #"http://itunes.apple.com
// But I do believe that it will be some sort of URL scheme that opens it specifically to the app on the app store.
// So without an example this is the best I can provide.
if([requestedURL isEqualToString:#"http://itunes.apple.com"]) {
// or if([requestedURL rangeOfString:#"itunes.apple.com"].location==0) {
// What is happening here is that if the request url that is being request is
// "http://mp3skull.com/mp3/nirvana.html" then we don't want to continue with the request so stop.
return NO;
}
// Otherwise for all other requests continue
return YES;
}
Remember you will need to set the delegate on your UIWebView as this method is a UIWebViewDelegate method - see Apple Documentation on UIWebViewDelegate for more information
Yes it happens, some times when you click on some links, the application will open another application.
Because, those links contain other app schemas. (link)
so, to disable opening such url-schemas, we have to detect them and not load them.
As appStore has "itunes.apple.com",
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString *requestedURL = [[request URL] absoluteString];
if([requestedURL rangeOfString:#"itunes.apple.com"].location==0) {
return NO;
}
return YES;
}
I´ve a small app with a UIWebView for web surfing in it. On some pages opens the Appstore for promotional purposes (that is annoying). How can i prevent that? Is there a special method? or just fake the browserid?
http://bjango.com/articles/ituneslinks/
here is the complete reference for link formation of the appstore, itunes.
from above reference link, apple.com is common for all kind of links.
So we can create regex or simply search string "apple.com" from url and avoid to load in webview.
If you wanna,use without regex following code may be help you :
-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *currentURL = request.URL;
NSString *urlString = url.absoluteString;
NSRange range = [urlString rangeOfString:#"apple.com"];
if (range.location != NSNotFound)
return YES;
else
return NO;
}
Use UIWebViewDelegate method webView:shouldStartLoadWithRequest:navigationType: to detect what URLs are getting loaded in the webview. App store URLs usually contain itunes.apple.com or phobos.apple.com.
When you encounter such urls are clicked, you can return NO from the web view delegate method to stop loading the url.
Hope that helps!
Use the following UIWebView Delegate method for this :
-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *currentURL = request.URL;
NSString *urlString = url.absoluteString;
NSRange range = [urlString rangeOfString:#"https://itunes.apple.com"]; // Change URL if other than this.
if (range.location != NSNotFound)
return YES;
else
return NO;
}
I have NSString as follows
NSString *textOutStations = [NSString stringWithFormat:#"Hello Everyone. Please check out website:<br> http://www.google.com/</br>"];
I want to show google.com as below in URL, as I will load this in UIWebView.
www.google.com
So, whenever user click it, It must open Safari in iPhone.
NSString *textOutStations = [NSString stringWithFormat:#"Hello Everyone. Please check out website:<br> http://www.google.com/"];
[self.webView loadHTMLString:textOutStations baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
Then in UIWebView delegate:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
// Opening safari
[[UIApplication sharedApplication] openURL:request.URL];
....
}
Try this one
NSString *textOutStations = #"<html><head><title></title></head><body><div> Hello Everyone. Please check out website:<br/> http://www.google.com/ </div></body></html>";
[self.webView loadHTMLString:textOutStations baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
This will help you......
You can not specify a URL with in a string and have it be clickable, this type of functionality is dependant on the object to which is using it, aka, UITextView UITextField UILabel UIWebView etc,
A UIWebview will show your url with in the webview it will not open the link in safari. IF you want to load it in ui web view, it's already ansered above, if you want to open it in safari, you have to do
[[UIAplication sharedApplication] openUrl:urlObject];
if you want to open it to be text with in a UITextView i would suggest this other stack overflow link here
I checked the link option in Attribute Inspector of UIWebView and it detected the link.
Method to OPEN in SAFARI...
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if ( inType == UIWebViewNavigationTypeLinkClicked ) {
[[UIApplication sharedApplication] openURL:[inRequest URL]];
return NO;
}
return YES;
}
I'm starting to notice a change in the way that youtube videos are being loaded into UIWebViews and I wanted to know if this is behavior we should be expecting in the future and/or if we can replicate the previous functionality.
Comparison screenshot :
Old on the right, new on the left. The added youtube button allows users to leave the youtube video and go into the youtube web interface. I would like to be able to prevent the user from leaving the video being played.
I am currently using a category on UIWebView like this :
- (void)loadYouTubeEmbed:(NSString *)videoId
{
NSString* searchQuery = [NSString stringWithFormat:#"http://www.youtube.com/embed/%#?showinfo=0&loop=1&modestbranding=1&controls=0",videoId];
searchQuery = [searchQuery stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:searchQuery]];
[self loadRequest:request];
}
I've noticed that my query will respect either modestbranding=1 or showinfo=0 but not both at the same time. Will this change as the youtube redesign rolls out?
When the Youtube video is loaded, and webView:shouldStartLoadWithRequest:navigationType: is hit, you should be able to filter out that link so it won't proceed.
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ([[[request URL] absoluteString] isEqualToString:#"<URL String Youtube spits out when video selected>"]) {
NSLog(#"Blocking YouTube...");
return NO;
} else {
NSLog(#"Link is fine, continue...");
return YES;
}
}