[iOS] URL Scheme ์ฌ์ฉํ์ฌ ๋ค๋ฅธ ์ฑ๊ณผ ํต์ ํ๊ธฐ
URL Scheme๋ก ๋ค๋ฅธ ์ฑ๊ณผ ํต์ ํด๋ณด์
iOS์์๋ URL Scheme์ ํตํด ๋ค๋ฅธ ์ฑ๊ณผ ํต์ ์ด ๊ฐ๋ฅํฉ๋๋ค!
URL Scheme์ ํตํด ๋ค๋ฅธ ์ฑ์ ์คํ์ ์์ฒญํ๊ฑฐ๋ ๊ฐ๋จํ ๋ฐ์ดํฐ๋ฅผ ์ ๋ฌํ ์ ์์ต๋๋ค.
์๋ฅผ ๋ค์ด ์ ํํ๊ณ ์ถ์ ๋ฒํธ๋ฅผ ์ ๋ ฅํ๋ฉด ๋ฐ๋ก ์ ํ ์ดํ๋ก ์ฐ๊ฒฐ๋์ด ์ ํ๋ฅผ ํ ์ ์์ต๋๋ค.
*์ค์ ๊ธฐ๊ธฐ๋ก ํ ์คํธ ๊ฐ๋ฅํฉ๋๋ค. ์๋ฎฌ๋ ์ดํฐ์์๋ sms๋ง ๊ฐ๋ฅ!
๐ฅ iOS Built-in URL Scheme
iOS๋ ๊ธฐ๋ณธ์ผ๋ก ์ค์น๋ ๋ฉ์ผ, ์ ํ, ๋ฉ์์ง ์ง๋ ์ฑ๊ณผ ํต์ ํ ์ ์๋ ๋ด์ฅ URL Scheme์ ์ ๊ณตํฉ๋๋ค.
์์ธํ ์ ๋ณด์ ์ฌ์ฉ๋ฒ์ ์๋ ์ฌ์ดํธ์์ ๋ณผ ์ ์์ต๋๋ค. ๐
About Apple URL Schemes
About Apple URL Schemes This document describes several URL schemes that are supported by system apps on iOS, macOS, and watchOS 2 and later. Native iOS apps and web apps running in Safari on any platform can use these schemes to integrate with system apps
developer.apple.com
mailto:์ด๋ฉ์ผ์ฃผ์ | ๋ฉ์ผ ์ฑ์ ํตํด ์๋ก์ด ๋ฉ์ผ ์์ฑ ํ๋ฉด ํ์ |
tel://์ ํ๋ฒํธ | ์ ํ ์ฐ๊ฒฐ |
sms://์ ํ๋ฒํธ | ๋ฉ์์ง ์ฐ๊ฒฐ |
facetime://FaceTImeID | FaceTime ์ฐ๊ฒฐ |
http://์น์ฌ์ดํธ URL https://์น์ฌ์ดํธ URL |
Safari ์ฑ์ ํตํด ์น์ฌ์ดํธ ํ์ |
http://maps.apple.com/?q=๊ฒ์์ด http://maps.apple.com/?ll=์๋, ๊ฒฝ๋ |
์ง๋ ์ฑ์ ํตํด ์ง์ญ ํ์ |
์ฑ์ด๋ฆ: | ์ด๋ํ๊ณ ์ถ์ ์ฑ์ผ๋ก ์ฐ๊ฒฐ |
๐ฅ OpenURL ์ฌ์ฉํ์ฌ ๋ค๋ฅธ ์ฑ๊ณผ ํต์ ํ๊ธฐ - 1. ๊ธฐ๋ณธ์ฑ
1. ์์ ์ํ๋ url scheme ํ์์ ๋ง๊ฒ URL ์ธ์คํด์ค ์์ฑ
- ์ ํ ๊ฑธ๊ธฐ : tel://010-1234-5678
- ๋ฉ์ผ ๋ณด๋ด๊ธฐ : mailto:honggildung@test.com
- ๋ฌธ์ ๋ณด๋ด๊ธฐ : sms://010-5678-1234
- ๋งํฌ ์ด๋ : https://naver.com
2. canOpenURL(_:) ๋ฉ์๋๋ฅผ ํตํด์ URL ์ฒด๊ณ๋ฅผ ์ฒ๋ฆฌํ๋ ๋ฐ ์ฑ์ ์ฌ์ฉํ ์ ์๋์ง ์ฌ๋ถ ํ์ธ
func canOpenURL(_ url: URL) -> Bool
3. open(_:options:completionHandler:) ๋ฉ์๋๋ฅผ ํธ์ถํด์ ๋ค๋ฅธ ์ฑ ํธ์ถ
func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey : Any] = [:], completionHandler completion: ((Bool) -> Void)? = nil)
*- (BOOL)openURL:(NSURL *)url; ์ iOS10์์ deprecate ๋จ
Swift
let url = "sms://01012345678"
if let openApp = URL(string: _url), UIApplication.shared.canOpenURL(openApp) {
// ๋ฒ์ ๋ณ ์ฒ๋ฆฌ
if #available(iOS 10.0, *) {
UIApplication.shared.open(openApp, options: [:], completionHandler: nil)
}
else {
UIApplication.shared.openURL(openApp)
}
}
//์คํค๋ง๋ช
์ ์ฌ์ฉํด ์ธ๋ถ์ฑ ์คํ์ด ๋ถ๊ฐ๋ฅํ ๊ฒฝ์ฐ
else {
print("[goDeviceApp : ๋๋ฐ์ด์ค ์ธ๋ถ ์ฑ ์ด๊ธฐ ์คํจ]")
print("๋งํฌ ์ฃผ์ : \(_url)")
}
}
Objective-C
NSURL *myURL = [NSURL URLWithString:@"tel:010-1234-5678"];
if ([UIApplication.sharedApplication canOpenURL:url]) {
[UIApplication.sharedApplication openURL:url];
}
๐ฅ OpenURL ์ฌ์ฉํ์ฌ ๋ค๋ฅธ ์ฑ๊ณผ ํต์ ํ๊ธฐ - 2. ๋ค๋ฅธ์ฑ
๋ค๋ฅธ์ฑ๊ณผ์ ํต์ ์ ์ํด์๋ ๋ค์ ๊ณผ์ ์ ์ถ๊ฐ์ ์ผ๋ก ์งํํฉ๋๋ค.
์๋ก kakaotalk์ ์คํํด ๋ณด๊ฒ ์ต๋๋ค !
1. info.plist์ ์๋ ํญ๋ชฉ์ ์ถ๊ฐ
info.plist์ ์๋ ํญ๋ชฉ์ ์ถ๊ฐํ์ฌ ๋ค๋ฅธ ์ฑ์ ํธ์ถํ ์ ์๋ ๊ถํ์ ์ป์ต๋๋ค.
LSApplicationQueriesSchemes์ ํ์ํญ๋ชฉ์ผ๋ก ํธ์ถํ ์ฑ ์ด๋ฆ์ ์ ์ต๋๋ค.
Info.plist์ ์ด๋ฅผ ์ถ๊ฐํด์ฃผ์ง ์์ผ๋ฉด ์๋์ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํฉ๋๋ค.
2. ํธ์ถํ๊ธฐ
ํธ์ถ์ ์๋์ ๊ฐ์ด url์ ๋ค๋ฅธ์ฑ ์ด๋ฆ์ ๋ฃ๊ณ ํธ์ถ ๋ฐฉ์์ ์์ ๊ฐ์ต๋๋ค.
let _url = "kakaotalk:"
[ํ ์คํธ ํ๋ฉด]