2

I want to launch safari browser from my IOS app with an specific url when I press a button.

Is that possible?

david
  • 200
  • 1
  • 14
  • 1
    possible duplicate of [launch safari from iphone app](http://stackoverflow.com/questions/822599/launch-safari-from-iphone-app) – Andy E Feb 10 '11 at 13:02

3 Answers3

11
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];
Bogatyr
  • 19,255
  • 7
  • 59
  • 72
  • -[LoginWindow linkWebPitjat:]: unrecognized selector sent to instance 0x650b9f0 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LoginWindow linkWebPitjat:]: unrecognized selector sent to instance 0x650b9f0' – david Feb 10 '11 at 13:19
  • ok I found the problem, and is not related with UIApplication...silly of me.. thank you for your help. – david Feb 10 '11 at 13:31
1

Use this code for launching the URL in the Safari Browser,

NSString* url = @"http://example.com";

UIApplication* app = [UIApplication sharedApplication];
[app openURL:[NSURL URLWithString:url]];
abatishchev
  • 98,240
  • 88
  • 296
  • 433
Splendid
  • 1,061
  • 6
  • 16
0

Sure you can!

Use the - (BOOL)openURL:(NSURL *)url method of UIApplication. You can get an instance of UIApplication using the static method + sharedApplication.

James Bedford
  • 28,702
  • 8
  • 57
  • 64
  • is it possible that I didnt have this method on my AppDelegate? – david Feb 10 '11 at 13:21
  • You're getting confused - I'm referring to the class UIApplication, of which your AppDelegate class is a delegate. These are two different classes, and thus in your program will be two different objects. Delegation is a relationship between classes and forms its own design pattern. I suggest you read about the delegation design pattern if this is confusing you. – James Bedford Feb 10 '11 at 13:23