์๋ ํ์ธ์ Foma ์ ๋๋ค!!
2019 WWDC์์ ๋ฐํํ Sign in with apple์ ๋ํด์ ์์๋ณผ๊ฑด๋ฐ์.
๋ฐํ์ ๋์์ Apple์ ์๋ก์ด ๊ฐ์ด๋ ๋ผ์ธ์ ์ถ๊ฐํ๋๋ฐ
๋ฐ๋ก ํ์ฌ ์์ ๋ก๊ทธ์ธ์ด ์๋ค ๋ฉด Apple ๋ก๊ทธ์ธ์ ํ์๋ก ์ ๊ณตํด์ผ ํ๋ค๋ ๊ฒ์ด์ฃ !
๊ทธ๋ฌ๋๊น "ํ์ฌ ๋ก๊ทธ์ธ์ ์ง์ํ ๊ฑฐ๋ฉด ์ฐ๋ฆฌ๊บผ๋ ๋ฌด์กฐ๊ฑด ์ง์ํด!! " ๋ผ๋ ๊ฒ์ด์ฃ .
๊ทธ๋ฌ๋ฉด ๊ตฌํํ๊ธฐ์ ์์ ๊ฐ์ฅ ๋จผ์ ํ์ํ ๊ฒ์ ์ ํ ๊ฐ๋ฐ์ ๊ณ์ ์ ๋๋ค.
์ ํ ๊ฐ๋ฐ์ ๊ณ์ ์ด ์์ด์ผ Sign in with apple ๊ถํ์ ์ป์ ์ ์์ด์ ใ
๊ฐ๋ฐ์ ๊ณ์ ๋ฑ๋ก๋ฐฉ๋ฒ์ ์๋ ์ฌ์ดํธ๋ฅผ ์ฐธ๊ณ ํด์ฃผ์ธ์!
Apple Developer ์ฑ์์ ๊ณ์ ๋ฑ๋ก ๋ฐ ๊ด๋ฆฌํ๊ธฐ - ์ง์ - Apple Developer
๋ฌธ์ํ๊ธฐ ์ด๋ป๊ฒ ๋์๋๋ฆด ์ ์๋์ง ์๋ ค์ฃผ์๋ฉด ํธ๋ํฐ์ด๋ ์ด๋ฉ์ผ์ ํตํด ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์ฐพ์๋๋ฆฝ๋๋ค. ์ง์๋ฐ๊ธฐ
developer.apple.com
๊ฐ๋ฐ์ ๊ณ์ ๋ฑ๋ก์ด ์๋ฃ๋์๋ค๋ฉด Xcode๋ก ์ด๋ํด์ฃผ์ธ์
Xcode
ํด๋น ํ๋ก์ ํธ์ Targets - Signing & Capabilities๋ก ์ด๋ํด์ค๋๋ค.
๊ทธ๋ฌ๋ฉด ์๋ ๋ ธ๋์์ผ๋ก ํ์ํด๋์ ๊ฒ์ฒ๋ผ +Capability๊ฐ ๋ณด์ผ๊ฑด๋ฐ ์ด๊ฒ์ ๋๋ฅด๊ณ Sign in with Apple์ ์ ํํด ์ถ๊ฐํด์ค๋๋ค.
์ถ๊ฐ๊ฐ ๋์๋ค๋ฉด ์๋์ฒ๋ผ Sign in with Apple์ด ์๊ธธ๊ฑฐ์์!
StoryBoard
StoryBoard๋ก ์ด๋ํด์ Apple Login Button ์ญํ ์ ํ Button์ ๋ง๋ค์ด์ค๋๋ค.
Button์ ํด๋์ค๋ ASAuthorizationAppleIDButton ์ผ๋ก ์ค์ ํด์ค๋๋ค.
ViewController
ViewController์ ๋ฒํผ์ ์ฐ๊ฒฐ์์ผ์ฃผ๊ณ AuthenticationServices๋ฅผ importํด์ค๋๋ค.
์ ๊ทธ๋ฆฌ๊ณ ์ค์ํ ๊ฑด ์ ํ๋ก๊ทธ์ธ์ iOS 13.0๋ฒ์ ์ดํ๋ถํฐ ์ง์ํ๋ฏ๋ก ViewController์ ๋ฐ๋์ @available(iOS 13.0,*)์ ๋ฃ์ด์ค์ผํฉ๋๋ค.
๊ทธ๋ฆฌ๊ณค AppleLogin ๋๋ฆฌ๊ฒ์ดํธ๋ฅผ ๋จผ์ ๋ง๋ค์ด์ค์๋ค!
๋๊ฐ์ง ํจ์๊ฐ ํ์ํ๋ฐ ํ๋๋ ๋ก๊ทธ์ธ์ด ์ฑ๊ณตํ์ ๋์ ์๋ฌ๊ฐ ์์ ๋ ์ ๋๋ค.
didCompleteWithAuthorization ํจ์๋ ๋ก๊ทธ์ธ์ด ์ฑ๊ณตํ์ ๋ ํธ์ถ๋๋๋ฐ ์ฌ๊ธฐ์ Crendential์ ๋ง๋ค์ด์ฃผ๊ณ ์ ์ ์ด๋ฆ๊ณผ ์ด๋ฉ์ผ์ ๋ฐ์์ฌ ์ ์์ต๋๋ค!
didCompleteWithError ํจ์๋ error๊ฐ ๋ฐ์ํ์ ๋ ํธ์ถ๋๋ ํจ์์ ๋๋ค.
๊ทธ ๋ค์์ผ๋ก ASAuthorizationControllerPresentationContextProviding๋ผ๋ ๋๋ฆฌ๊ฒ์ดํธ๋ฅผ ๋ง๋ค์ด์ค์ผํ๋๋ฐ์.
์ด๊ฒ์ ๋ฐ๋ก AppleLogin๋ฒํผ์ ๋๋ ์ ๋ ์๋์ ๋จ๋ ์๋ฆผ์ฐฝ๊ฐ์๊ฑฐ ๋ณด์ จ์ฃ ? ๋ฐ๋ก ๊ทธ๊ฑฐ์ ๋๋ค.
์ด ์๋ฆผ์ฐฝ์ Anchor๋ฅผ ํ์ฌ view์ window๋ก ์ค์ ํด์ค์๋ค.
์ ์ด์ ๋๋ฆฌ๊ฒ์ดํธ๋ฅผ ๋ชจ๋ ๋๋ง์ณค๋ค๋ฉด ๊ทธ ๋ค์์ผ๋ก appleLogin ๋ฒํผ์ ๋๋ ์ ๋ ์ด๋ค ๊ฒ์ ํด์ผํ ์ง ๊ตฌํํด์ค์ผํ๊ฒ ์ฃ ?
appleLoginButton์ addTarget์ ๋ฌ์์ฃผ๊ณ @objc๋ฉ์๋๋ก appleLogInButtonTapped()์ ๋ง๋ค์ด์ค๋๋ค.
๊ฐ๋จํ๊ฒ ์ค๋ช ๋๋ฆฌ๋ฉด addTarget์ ์ด ๋ฒํผ์ ๋๋ ์ ๋ ์ค์ ํ #selector(@objc ๋ฉ์๋)๋ฅผ ์คํ์์ผ์ค๋ผ๊ณ ์ดํดํ์๋ฉด ๋ฉ๋๋ค!
appleLoginButtonTapped() ์ฆ appleLogin๋ฒํผ์ ๋๋ ์ ๋ ์ค์ ํด์ค์ผ ํ ๊ฒ ๋ช๊ฐ์ง ์์ด์
์ฒซ๋ฒ์งธ๋ก authorizationProvider๋ฅผ ๋ง๋ค์ด์ ์์ฒญ์ ํด์ผํด์.
์ํ๋ ์ ๋ณด๋ ๊ฐ์ด ๋ฃ์ด์ค์๋ค. (email์ด๋ name ๋ฑ)
๊ทธ ๋ค์์ผ๋ก authorizationController๋ฅผ ๋ง๋ค์ด์ค๋ค delegate๋ฅผ ํ์ฌ ViewController๋ก ํด์ฃผ๊ณ ์๊น ๋ง๋ค์ด์ค
presentationContextProvider ๋๋ฆฌ๊ฒ์ดํธ ๋ํ ํ์ฌ ViewController๋ก ์ค์ ํด์ค ๋ค performRequests()๋ฅผ ํด์ค๋๋ค.
GIF
๋ชจ๋ ์ค์ ์ด ๋๋๊ณ ์คํ์์ผ์ฃผ๋ฉด ์๋์ ๊ฐ์ด ์ ํ๋ก๊ทธ์ธ์ด ์ ์์ ์ผ๋ก ์๋๋๋๊ฑธ ๋ณผ ์ ์์ต๋๋ค.
์ด๋ฉ์ผ๋ ์ ์์ ์ผ๋ก ์ถ๋ ฅ๋๋๊ฑธ ๋ณผ ์ ์์ต๋๋ค.
Source Code
fomagran/AppleLoginExample
์ ํ๋ก๊ทธ์ธ๊ตฌํ. Contribute to fomagran/AppleLoginExample development by creating an account on GitHub.
github.com
'๐ iOS > iOS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[iOS ๋ฉด์ ์ง๋ฌธ] ARC(Auto Reference Counting)๋? (0) | 2020.11.21 |
---|---|
[iOS ๋ฉด์ ์ง๋ฌธ] Delegate์ Protocol (0) | 2020.11.16 |
[iOS ๋ฉด์ ์ง๋ฌธ]์ค์ ๋๋ฐ์ด์ค๊ฐ ์์ ๊ฒฝ์ฐ ํ ์ ์๋ ๊ฒ๊ณผ ์๋ ๊ฒ (3) | 2020.11.13 |
[iOS ๋ฉด์ ์ง๋ฌธ]Bounds์ Frame์ ์ฐจ์ด (0) | 2020.11.09 |
[iOS] @escaping (2) - ์ํ API ์์ ๋ก ์ฝ๊ฒ ์ดํดํ๊ธฐ (@escaping with movieAPI Example) (0) | 2020.11.01 |
๋๊ธ