hi all, i am new to iPhone. i want to open a url in my application. How can i do this task? please suggest me and provide some useful link
+2
A:
If you would like to open and just get the data from the URL, you could use NSString:
NSString *ans = [NSString stringWithContentsOfURL:url];
If what you are trying to get is an XML from a URL, you can directly use NSXMLParser:
NSURL *url = [[NSURL alloc] initWithString:urlstr];
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
// parse here
[parser release];
[url release];
On the other hand, if by opening you mean, open a URl in an embedded browser, you could use UIWebView class.
Pablo Santa Cruz
2009-11-01 10:34:53
+2
A:
If you want to open the URL in Safari (and exit your application) you can use the openURL method of UIApplication
If you'd rather have it handled inside of your app, use UIWebView.
bpapa
2009-11-01 13:34:12
+1
A:
Apparently the link given above is outdated (apple just redirects to the developer pages index).
The quick and simple code snippet is:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://www.google.com"]];
The updated link: UIApplication Class Reference
Chris R
2010-10-21 16:21:15