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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 08-26-2008, 09:35 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Ireland
Age: 21
Posts: 472
Question Push button to open link in safari

I know this is a very simple bit of code but I'm new to Objective C and can't find an answer on the forums or a simple answer in the documentation.

I want to push a button which then opens a URL I specify in safari. I just want it to load the URL in safari. My application does not need to stay open.

If you can help me thanks.
__________________
On the iOS App Store
kieran12 is offline   Reply With Quote
Old 08-26-2008, 09:46 AM   #2 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Ireland
Age: 21
Posts: 472
Wink

I have found the answer myself with some guessing and looking further at the documentation. The code I was looking or was:

Code:
 [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://www.google.co.uk"]];
where Google is replaced with your own URL.
__________________
On the iOS App Store
kieran12 is offline   Reply With Quote
Old 08-31-2008, 08:27 PM   #3 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 28
Default

Very helpful. Thanks.
ae6rt is offline   Reply With Quote
Old 08-31-2008, 08:32 PM   #4 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Ireland
Age: 21
Posts: 472
Default

your welcome
__________________
On the iOS App Store
kieran12 is offline   Reply With Quote
Old 02-21-2009, 05:08 PM   #5 (permalink)
New Member
 
Join Date: Nov 2008
Location: Germany
Posts: 9
Default

Do you have to do any clean up when you use this code?
Does your application terminate properly when you open a link
in Safari?

aboy
aboy is offline   Reply With Quote
Old 10-26-2009, 02:30 PM   #6 (permalink)
Registered Member
 
Join Date: May 2009
Location: Denver CO
Posts: 88
Default

Quote:
Originally Posted by aboy View Post
Do you have to do any clean up when you use this code?
Does your application terminate properly when you open a link
in Safari?

aboy
Works flawlessly for me. Application terminates and forwards you to whatever site you are going to. Issue is if the user returns to your app, you have to store the current state and open the app back up properly.
seriessix is offline   Reply With Quote
Old 11-11-2009, 02:55 AM   #7 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 19
Default

How can I do the same thing but open an address in Google Maps? Ideally I'd like the button to pull info from a SQlite Database.

For instance, using this app as an example:

iPhone SDK Tutorial: Reading data from a SQLite Database | dBlog.com.au

I'd like to have a table like this one and when you clicked on a "animal" name it would load the Google Map instead of going to the "animal's" info page.

Thoughts? Suggestions? code snippets?


Quote:
Originally Posted by kieran12 View Post
I have found the answer myself with some guessing and looking further at the documentation. The code I was looking or was:

Code:
 [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://www.google.co.uk"]];
where Google is replaced with your own URL.
mrshow555 is offline   Reply With Quote
Old 11-11-2009, 04:26 AM   #8 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Ireland
Age: 21
Posts: 472
Default

Quote:
Originally Posted by mrshow555 View Post
How can I do the same thing but open an address in Google Maps? Ideally I'd like the button to pull info from a SQlite Database.

For instance, using this app as an example:

iPhone SDK Tutorial: Reading data from a SQLite Database | dBlog.com.au

I'd like to have a table like this one and when you clicked on a "animal" name it would load the Google Map instead of going to the "animal's" info page.

Thoughts? Suggestions? code snippets?
I'm not sure about the SQL part but to open an address using the maps app you just need to put in the URL from google maps. It also works like this for youtube. If you put in a Youtube URL it will open the Youtube app.
__________________
On the iOS App Store
kieran12 is offline   Reply With Quote
Old 11-11-2009, 12:54 PM   #9 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 19
Default

Quote:
Originally Posted by kieran12 View Post
I'm not sure about the SQL part but to open an address using the maps app you just need to put in the URL from google maps. It also works like this for youtube. If you put in a Youtube URL it will open the Youtube app.
Great, thanks! I guess I can put the google map url in the database and then just need to figure out how to have the link code refer to the database cell with the url...
mrshow555 is offline   Reply With Quote
Old 11-11-2009, 12:58 PM   #10 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Ireland
Age: 21
Posts: 472
Default

Quote:
Originally Posted by mrshow555 View Post
Great, thanks! I guess I can put the google map url in the database and then just need to figure out how to have the link code refer to the database cell with the url...
Yeh, so just pull the data (url) from the database, store it as an NSString and then refer to that NSString instead of a static piece of code in the openURL method.
__________________
On the iOS App Store
kieran12 is offline   Reply With Quote
Reply

Bookmarks

Tags
newbie, safari, site, url, web

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: 236
16 members and 220 guests
@sandris, ADY, Alsahir, dacapo, Dani77, djohnson, HemiMG, jansan, JasonR, MarkC, mer10, prchn4christ, ryandb2, smethorst, tomtom100
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,228
Posts: 380,762
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

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