이것은 명백한 질문이지만 iPhone 앱에서 Safari 브라우저를 시작할 수 있습니까?
답변
다음과 같아야합니다.
NSURL *url = [NSURL URLWithString:@"http://www.stackoverflow.com"];
if (![[UIApplication sharedApplication] openURL:url]) {
NSLog(@"%@%@",@"Failed to open url:",[url description]);
}
답변
UIApplication에는 openURL이라는 메소드가 있습니다.
예:
NSURL *url = [NSURL URLWithString:@"http://www.stackoverflow.com"];
if (![[UIApplication sharedApplication] openURL:url]) {
NSLog(@"%@%@",@"Failed to open url:",[url description]);
}
답변
당신은 이것을 사파리에서 URL을 열 수 있습니다 :
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.google.com"]];
답변
iOS 10에는 완료 처리기 와 다른 방법이 있습니다 .
목표 C :
NSDictionary *options = [NSDictionary new];
//options can be empty
NSURL *url = [NSURL URLWithString:@"http://www.stackoverflow.com"];
[[UIApplication sharedApplication] openURL:url options:options completionHandler:^(BOOL success){
}];
빠른:
let url = URL(string: "http://www.stackoverflow.com")
UIApplication.shared.open(url, options: [:]) { (success) in
}
답변
누군가 Swift 버전을 사용할 수 있습니다.
빠른 2.2에서 :
UIApplication.sharedApplication().openURL(NSURL(string: "https://www.google.com")!)
그리고 3.0 :
UIApplication.shared().openURL(URL(string: "https://www.google.com")!)
답변
신속한 4와 5에서 OpenURL은 감가 상각되므로 쉽게 수행 할 수있는 방법은
if let url = URL(string: "https://stackoverflow.com") {
UIApplication.shared.open(url, options: [:])
}
을 사용할 수도 있습니다 SafariServices
. 앱 내의 Safari 창과 같은 것.
import SafariServices
...
if let url = URL(string: "https://stackoverflow.com") {
let safariViewController = SFSafariViewController(url: url)
self.present(safariViewController, animated: true)
}
답변
Swift 3.0에서는이 클래스를 사용하여 통신에 도움을 줄 수 있습니다. 프레임 워크 관리자는 이전 답변을 더 이상 사용하지 않거나 제거했습니다.
UIKit 가져 오기 InterAppCommunication {클래스 정적 func openURI (_ URI : 문자열) { UIApplication.shared.open (URL (string : URI) !, 옵션 : [:], completionHandler : {(succ : Bool) in print ( "Complete! Success? \ (succ)")}) } }
![](http://daplus.net/wp-content/uploads/2023/04/coupang_part-e1630022808943-2.png)