This might be a rather obvious question, but can you launch the Safari browser from an iPhone app?
surtyaar
should be the following :
NSURL *url = [NSURL URLWithString:@"http://www.stackoverflow.com"];
if (![[UIApplication sharedApplication] openURL:url]) {
NSLog(@"%@%@",@"Failed to open url:",[url description]);
}
Brad The App Guy
UIApplication has a method called openURL:
example:
NSURL *url = [NSURL URLWithString:@"http://www.stackoverflow.com"];
if (![[UIApplication sharedApplication] openURL:url]) {
NSLog(@"%@%@",@"Failed to open url:",[url description]);
}
Dhaval Parmar
you can open the url in safari with this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.google.com"]];
With iOS 10 we have one different method with completion handler:
ObjectiveC:
NSDictionary *options = [[NSDictionary alloc] init];
//options can be empty
NSURL *url = [NSURL URLWithString:@"http://www.stackoverflow.com"];
[[UIApplication sharedApplication] openURL:url options:options completionHandler:^(BOOL success){
}];
Maybe someone can use the Swift version:
In swift 2.2:
UIApplication.sharedApplication().openURL(NSURL(string: "https://www.google.com")!)
And 3.0:
UIApplication.shared().openURL(URL(string: "https://www.google.com")!)
In Swift 3.0, you can use this class to help you communicate with. The framework maintainers have deprecated or removed previous answers.
import UIKit class InterAppCommunication { static func openURI(_ URI: String) { UIApplication.shared.open(URL(string: URI)!, options: [:], completionHandler: { (succ: Bool) in print("Complete! Success? \(succ)") }) } }
In swift 4, as OpenURL is depreciated, an easy way of doing it would be just
if let url = URL(string: "https://stackoverflow.com") {
UIApplication.shared.open(url, options: [:]) }
来源:https://stackoverflow.com/questions/822599/how-can-i-launch-safari-from-an-iphone-app