728x90
다른 앱 또는 웹페이지 연결 수단으로 URL Scheme을 통해 다른 앱의 실행을 요청하거나 간단한 데이터를 전달 할 수 있다.
<URL Scheme 사용 과정>
1. URL Scheme 문자열을 통해 URL 인스턴스 생성
NSString * url = ["URL Scheme url 입력" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
2. UIApplication의 canOpenURL 메서드를 통해 URL Scheme의 유효성 확인
[[UIApplication sharedApplication] canOpenURL:"URL입력"];
3. 유효한 URL Scheme으로 확인된 경우 openURL 메서드 호출
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:"URL 입력"] options:@{} completionHandler:nil];
참고 :
https://blog.naver.com/PostView.nhn?isHttpsRedirect=true&blogId=horajjan&logNo=220893876471
Swift
//URLScheme 문자열
let kakao = "kakaotalk://"
//URL 인스턴스
let kakaoURL = NSURL(string: kakao)
//canOpenURL(_:) 앱을 사용할 수 있는지 여부 확인
if (UIApplication.shared.canOpenURL(kakaoURL! as URL)) {
// 앱 열기
UIApplication.shared.open(kakaoURL! as URL)
}
DispatchQueue.main.async {
if let url = URL(string: "itms-apps://itunes.apple.com/app/\(appleID)"), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
}
만약 URL Scheme을 모른다면, https://gofo-coding.tistory.com/entry/URL-Scheme
* URL Scheme 대신 BundleID를 알고 있다면 URL Scheme 자리에 BundleID를 적어주면 됨
728x90
'iOS > iOS' 카테고리의 다른 글
네이버 지도 API (0) | 2023.02.15 |
---|---|
keyboard 높이 (1) | 2023.02.01 |
present된 ViewController에 push (0) | 2023.01.26 |
Expandable tableView Cell(셀 확장) (0) | 2023.01.26 |
빌드한 앱의 권한 제어 (0) | 2023.01.11 |
댓글