Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-22-2009, 03:33 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 157
starwarsdevwookie59 is on a distinguished road
Default Confirm link to Safari from WebView

I have a UIWebView set up to launch any clicked links in Safari. I know the code to make a UIAlert but i cant find a way to implement it here. Basically I want to click on a link. It loads nothing. Asks you if you want to go to Safari. If you click OK it does... If you click cancel, it does nothing... Heres my code: Any ideas? Thanks!

- (BOOL)webViewUIWebView *)webView shouldStartLoadWithRequestNSURLRequest *)request navigationTypeUIWebViewNavigationType)navigation Type;
{
NSURL *loadURL = [ [ request URL ] retain ]; // retain the loadURL for use
if ( ( [ [ loadURL scheme ] isEqualToString: @"http" ] || [ [ loadURL scheme ] isEqualToString: @"https" ] ) && ( navigationType == UIWebViewNavigationTypeLinkClicked ) )
return ![ [ UIApplication sharedApplication ] openURL: [ loadURL autorelease ] ];

[ loadURL release ];
return YES; // URL is not http/https and should open in UIWebView

}
starwarsdevwookie59 is offline   Reply With Quote
Old 10-08-2009, 08:14 AM   #2 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 49
schimanke is on a distinguished road
Default

Just stumbled across this thread. Maybe I'm too late but here is how I would do it:

Code:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

{
	NSURL *loadURL = [[request URL] retain];
	
	// Check navigationType. Else this alert will be visible on every load of UIWebView 
	if ( ( [ [ loadURL scheme ] isEqualToString: @"http" ] || [ [ loadURL scheme ] isEqualToString: @"https" ] ) && ( navigationType == UIWebViewNavigationTypeLinkClicked ) )
	{
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Open Safari?" 
													   message :@"Whatever you want to put here..."
													   delegate:self 
											  cancelButtonTitle: @"No"
											  otherButtonTitles:@"Yes", nil];
		
		[alert show];
		[alert release];
		
		savedLink = [[request URL] retain];
		
		[loadURL release];
	} 
	else
	{
		[loadURL release];
		return YES;
	}
	return NO;
}
And then:

Code:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
	if(buttonIndex == 1)
	{
		[[UIApplication sharedApplication] openURL:savedLink];
	}
}
schimanke is offline   Reply With Quote
Reply

Bookmarks

Tags
alert, link, safari, webview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 318
10 members and 308 guests
chiataytuday, coolman, givensur, ipodphone, jbro, mediaspree, mottdog, mtl_tech_guy, Punkjumper, vilisei
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,882
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:19 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0