I am making an app for a charity and Apple's review guidelines state that all donations must be made outside of the app in Safari, except for SMS donations, which we're not doing anyway. How do I make a button, that when tapped, goes to a specific URL in Safari? Thanks for your help!
Asked
Active
Viewed 327 times
2 Answers
5
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"your.website.here"]];
And put it in an IBAction for your button.
There might be a problem connecting to your site try this:
NSURL *url = [NSURLWithString:@"your.website.here"];
if (![[UIApplication sharedApplication] openURL:url])
NSLog(@"%@%@",@"Failed to open url:",[url description]);
They actually have a post on it here:
-
Awesome, didn't know it was that simple, thanks for your help!! – Jack Humphries Aug 12 '11 at 04:17
-
That doesn't work. Nothing happens. I put a NSLog in the IBAction as well, and while I saw the NSLog, the app just sits there and does nothing. Safari does not open. – Jack Humphries Aug 12 '11 at 04:21
-
@Jack: Check to make sure there isn't a problem with connecting to the website. – Dair Aug 12 '11 at 04:26
3
You can use this code in button click event
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"your url"]];
it automatically opens in safari

Nipin Varma
- 384
- 1
- 7