๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐ŸŽ iOS/iOS Application

[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:"

 

[ํ…Œ์ŠคํŠธ ํ™”๋ฉด]

728x90
๋ฐ˜์‘ํ˜•