Saturday, May 25, 2013

UIApplication openURL example in objective c (iOS)


UIApplication openURL

Opens the resource at the specified URL.
- (BOOL)openURL:(NSURL *)url
Parameters
url
An object representing a URL (Universal Resource Locator). UIKit supports the http:, https:, tel:, and mailto: schemes.
Return Value of UIApplication openURL
YES if the resource located by the URL was successfully opened; otherwise NO.
Discussion of UIApplication openURL
The URL can locate a resource in the same or other application. If the resource is another application, invoking this method may cause the calling application to quit so the other one can be launched.
You may call canOpenURL: before calling this one to verify that there is an application that can handle it.
UIApplication openURL example.
NSString *urlString= glassbutton://com.yourcompany.glassbutton"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
UIApplication openURL example.
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@, Anchorage, AK",addressString];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ]];
UIApplication openURL example.
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@, Anchorage, AK",addressString];
NSString *escaped = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:escaped]];