iOS uses the built-in browser Safari to open web pages

When developing iOS, we need to open a certain web page, we can write a web page, or we can directly use the browser to open the URL

So how do we use the iOS built-in browser to open the URL?

as follows:


Use [[UIApplication sharedApplication]openURL
openURL:Open URL before ios 10


NSURL *URL = [NSURL URLWithString:@"http://www.baidu.com"];

[[UIApplication sharedApplication]openURL:URL];

After ios 9 use [[UIApplication sharedApplication] openURL: options: completionHandler: ];
 This function is executed asynchronously, but the callback in the completionHandler is called in the main queue.
openURL: Open URL
options: Used to verify whether the url and applicationConfigure are configured correctly. it's usable or not.
The only available @{UIApplicationOpenURLOptionUniversalLinksOnly:@YES}.
You don’t need to set nil, you need to use @{} to make it empty.
ompletionHandler: If not needed, it can be set to nil

 


NSURL *URL = [NSURL URLWithString:@"http://www.baidu.com"];


[[UIApplication sharedApplication]openURL:URL options:@{} completionHandler:^(BOOL success {
	  //  回调
 }];

 

 

 

Guess you like

Origin blog.csdn.net/zjpjay/article/details/88950627
Recommended