iOS

[iOS] ์•ฑ ๋‚ด์—์„œ ์ธ์Šคํƒ€๊ทธ๋žจ ์‹คํ–‰ํ•˜๊ธฐ (๋ฒ”์šฉ๋งํฌ Universal Link / UIApplication / URL scheme)

Forest Yun 2022. 3. 13. 18:17
728x90

 

 

๋ฌธ์ œ

์•ฑ ๋‚ด์—์„œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ด ์„ค์ •๋œ ์ธ์Šคํƒ€๊ทธ๋žจ ๊ณ„์ • ํ”„๋กœํ•„๋กœ ์ด๋™ํ•˜๊ธฐ

 

 

 

 

 

 

 

 

    @IBAction func tapBtnInstagram(_ sender: UIButton) { //1
        let instagram = "https://www.instagram.com/lazy_cookie_lazy" //2
        
        let instagramURL = NSURL(string: instagram) //3
        
        if UIApplication.shared.canOpenURL(instagramURL! as URL) { //4
            UIApplication.shared.open( //5
            instagramURL! as URL, 
            options: [:], 
            completionHandler: nil
            )
        }
    }

1. ์›ํ•˜๋Š” ๋ฒ„ํŠผ์˜ ์•ก์…˜ํ•จ์ˆ˜๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

 

2. ์ธ์Šคํƒ€๊ทธ๋žจ์˜ ๋ฒ”์šฉ๋งํฌ(universal links)๋ฅผ ํ”„๋กœํผํ‹ฐ์— ๋ฌธ์ž์—ด๋กœ ํ• ๋‹นํ•œ๋‹ค.

  • ๋ฒ”์šฉ ๋งํฌ๋Š” ๋”ฐ๋กœ ์‚ฌํŒŒ๋ฆฌ๋‚˜ ์›น์‚ฌ์ดํŠธ๋ฅผ ํ†ตํ•˜์ง€ ์•Š๊ณ  ๋ฐ”๋กœ ์•ฑ์„ ์‹คํ–‰์‹œํ‚ค๊ฑฐ๋‚˜ ๋ฐ์ดํ„ฐ๋ฅผ ์•ˆ์ „ํ•˜๊ฒŒ ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๋‹ค.  ๋ฒ”์šฉ ๋งํฌ๋Š” HTTP ๋˜๋Š” HTTPS ๋งํฌ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋งŒ์•ฝ ํ•ด๋‹น ์•ฑ์ด ์‚ฌ์šฉ์ž์˜ ํœด๋Œ€ํฐ์— ์„ค์น˜๋˜์–ด์žˆ์ง€ ์•Š๋‹ค๋ฉด ์‚ฌํŒŒ๋ฆฌ๋ฅผ ํ†ตํ•ด URL์ด ์‹คํ–‰๋œ๋‹ค.
  • https://developer.apple.com/documentation/xcode/allowing-apps-and-websites-to-link-to-your-content
 

Apple Developer Documentation

 

developer.apple.com

  • ์ธ์Šคํƒ€๊ทธ๋žจ์˜ ๋ฒ”์šฉ๋งํฌ ์ข…๋ฅ˜
๋ฒ”์šฉ ๋งํฌ ์ž‘์—…
ttps://www.instagram.com Instagram ์•ฑ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
https://www.instagram.com/create/story ์นด๋ฉ”๋ผ๊ฐ€ ์•„๋‹Œ ๊ธฐ๊ธฐ์—์„œ ์นด๋ฉ”๋ผ ๋ทฐ ๋˜๋Š” ์‚ฌ์ง„ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ผœ๊ณ  Instagram ์•ฑ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
https://www.instagram.com/p/{media_id} Instagram ์•ฑ์„ ์‹คํ–‰ํ•˜๊ณ  ์ง€์ •๋œ ID ๊ฐ’(int)๊ณผ ์ผ์น˜ํ•˜๋Š” ๊ฒŒ์‹œ๋ฌผ์„ ์ฝ์–ด๋“ค์ž…๋‹ˆ๋‹ค.
https://www.instagram.com/{username} Instagram ์•ฑ์„ ์‹คํ–‰ํ•˜๊ณ  ์ง€์ •๋œ ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๊ฐ’(string)๊ณผ ์ผ์น˜ํ•˜๋Š” Instagram ์‚ฌ์šฉ์ž๋ฅผ ์ฝ์–ด๋“ค์ž…๋‹ˆ๋‹ค.
https://www.instagram.com/explore/locations/{location_id} Instagram ์•ฑ์„ ์‹คํ–‰ํ•˜๊ณ  ์ง€์ •๋œ ID ๊ฐ’(int)๊ณผ ์ผ์น˜ํ•˜๋Š” ์œ„์น˜ ํ”ผ๋“œ๋ฅผ ์ฝ์–ด๋“ค์ž…๋‹ˆ๋‹ค.
https://www.instagram.com/explore/tags/{tag_name} Instagram ์•ฑ์„ ์‹คํ–‰ํ•˜๊ณ  ์ง€์ •๋œ ์ด๋ฆ„ ๊ฐ’(string)๊ณผ ์ผ์น˜ํ•˜๋Š” ํ•ด์‹œํƒœ๊ทธ์— ๋Œ€ํ•œ ํŽ˜์ด์ง€๋ฅผ ์ฝ์–ด๋“ค์ž…๋‹ˆ๋‹ค.

 

3. NSURL(string: )์„ ํ†ตํ•ด url ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

 

4.  ํ•ด๋‹น URL์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.

func canOpenURL(_ url: URL) -> Bool
์•ฑ์˜ URL scheme์„ ์‚ฌ์šฉ์—ฌ๋ถ€๋ฅผ Bool ํƒ€์ž…์œผ๋กœ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

5. ํ•ด๋‹น URL์„ ์‚ฌ์šฉํ•ด ์•ฑ์„ ์‹คํ–‰ํ•œ๋‹ค. ๋˜๋Š” ์‚ฌํŒŒ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•ด URL์„ ๊ฒ€์ƒ‰ํ•œ๋‹ค.

func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey : Any] = [:], completionHandler completion: ((Bool) -> Void)? = nil)
ํ•ด๋‹น URL์„ ๋น„๋™๊ธฐ์ ์œผ๋กœ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ์„ ์‹œ๋„ํ•œ๋‹ค.

 

 

 

 

 

 

 

 

 

์ธ์Šคํƒ€๊ทธ๋žจ ํ”ผ๋“œ ๊ณต์œ ํ•˜๊ธฐ
https://developers.facebook.com/docs/instagram/sharing-to-feed/
๋ฒ”์šฉ ๋งํฌ Universal Link
https://developer.apple.com/documentation/xcode/allowing-apps-and-websites-to-link-to-your-content
728x90