APNsTutorial-iOS

๐Ÿคจ
Apple Push Notification service tutorial

  • ๋‹จ์ˆœํžˆ ์ˆœ์„œ๋ฅผ ๋”ฐ๋ผ์„œ ๊ฐ€๋ฉด ๋  ์ค„ ์•Œ์•˜๋Š”๋ฐ ์•Œ์•„์•ผํ•  ๊ฒƒ๋„ ์žˆ์—ˆ๊ณ  ๊ฒฝ์šฐ์— ๋”ฐ๋ผ์„œ ์š”๊ตฌํ•˜๋Š” ํŒŒ์ผ๋„ ๋‹ฌ๋ž๋‹ค. ๊ทธ๋Ÿฌ๋‹ˆ ์ฒœ์ฒœํžˆ ์ฝ์–ด์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

  • ๋จผ์ € ์–ด๋–ค ์„œ๋ฒ„ ํ™˜๊ฒฝ์—์„œ ํ‘ธ์‰ฌ์•Œ๋ฆผ์„ ๋ณด๋‚ด์ค„ ๊ฑด์ง€ ๊ทธ๋ ‡๋‹ค๋ฉด server provider ๊ฐ€ ์š”๊ตฌํ•˜๋Š” ํŒŒ์ผ์€ ๋ฌด์—‡์ธ์ง€ ์•Œ๊ณ  ์ง„ํ–‰ํ•˜๊ธฐ๋ฅผ ๋ฐ”๋ž๋‹ˆ๋‹ค.


p8(์ธ์ฆํ‚ค) ,p12(์ธ์ฆ์„œ) ํŒŒ์ผ ๋ชจ๋‘ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์„ ์ •๋ฆฌํ–ˆ๋‹ค. APNs ํ‚ค๋Š”(p8) ๊ณ„์ •๋‹น 2๊ฐœ๊นŒ์ง€๋งŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ์–ด์„œ ๋‚˜๋Š” ๋ชป๋งŒ๋“ค์–ด๋ดค๊ณ  ์ถœ์ฒ˜๋ฅผ ์ฐธ๊ณ ํ–ˆ๋‹ค.

(์ฐธ๊ณ ๋กœ p8(์ธ์ฆํ‚ค)์€ ์ธ์ฆ๊ฐฑ์‹ ์„ ํ•˜์ง€ ์•Š์•„๋„ ๋˜๊ธฐ ๋•Œ๋ฌธ์— p12(์ธ์ฆ์„œ)๋ณด๋‹ค ์„ ํ˜ธํ•œ๋‹ค. ํŒŒ์ด์–ด๋ฒ ์ด์Šค์—์„œ๋Š” ๋‘˜ ๋‹ค ์ง€์›ํ•œ๋‹ค.)

์ดํ•ด๋ฅผ ์™„๋ฒฝํ•˜๊ฒŒ ํ•˜์ง€ ์•Š๋”๋ผ๋„ ์•„๋ž˜์˜ ๊ธ€์„ ๋จผ์ € ์ฝ์–ด๋ณด๋Š” ๊ฑธ ์ถ”์ฒœํ•œ๋‹ค.

[iOS] provider server์™€ APNs์˜ ์•ˆ์ „ํ•œ ์—ฐ๊ฒฐ์„ ์œ„ํ•œ ๋‘๊ฐ€์ง€ ๋ฐฉ๋ฒ•

โ—๏ธ
์ด์ œ ํ‘ธ์‰ฌ์•Œ๋ฆผ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ๊ณผ์ •์„ ์•Œ์•„๋ณด์ž

Apple Push Notification service (APNs) ์„ค์ •ํ•˜๊ธฐ

APNs ๋ž€? iOS ์—์„œ ์ง€์›ํ•˜๋Š” ํ‘ธ์‰ฌ์•Œ๋ฆผ์ด๋‹ค.

1. CSR ๋ฐœ๊ธ‰

CSR (Certificate Signing Request : ์ธ์ฆ์„œ ์„œ๋ช… ์š”์ฒญ)

  • ํ‚ค์ฒด์ธ์„ ์—ฐ๋‹ค. ํ‚ค์ฒด์ธ ์ ‘๊ทผ – ์ธ์ฆ์„œ ์ง€์› – ์ธ์ฆ ๊ธฐ๊ด€์—์„œ ์ธ์ฆ์„œ ์š”์ฒญ

  • ์ด๋ฉ”์ผ ์ฃผ์†Œ์™€ ์ผ๋ฐ˜ ์ด๋ฆ„์„ ์ž…๋ ฅํ•ด์ฃผ๊ณ  ์š”์ฒญํ•ญ๋ชฉ์„ ๋””์Šคํฌ์— ์ €์žฅ๋จ ์ด๋ผ๊ณ  ์ฒดํฌํ•ด์ค€๋‹ค.

  • ๊ณ„์† ์ง„ํ–‰ํ•˜๋ฉด ๋œ๋‹ค.

CertificateSigningRequest.certSigningRequest ๋ช…์œผ๋กœ ํŒŒ์ผ์ด ์ƒ์„ฑ๋œ๋‹ค.

2. App ID ๋“ฑ๋ก ๋ฐ Push Notification ํ™œ์„ฑํ™”

Apple Developer

apple developer ํ™ˆํŽ˜์ด์ง€์— ์ ‘์†.

(Account
โžก๏ธ
Certificates, IDs & Profiles
โžก๏ธ
Identifiers)

  • Identifiers ๋“ฑ๋ก

  • App IDs ์„ ํƒ

  • Register an App ID

Bundle ID ๋Š” ํ”„๋กœ์ ํŠธ์—์„œ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

  • ํ•˜๋‹จ์— Push Notifications ์„ ํƒ

๊ทธ๋ฆฌ๊ณ  ๋งŒ๋“ค์–ด์ง„ App ID ๋ฅผ ํ™•์ธํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

A. p12 ์ธ์ฆ์„œ ๋งŒ๋“ค๊ธฐ

p8 ์ธ์ฆํ‚ค๋ฅผ ๋งŒ๋“ค๋ ค๋ฉด B ๋กœ ๊ฐ€๋ฉด ๋œ๋‹ค.

A-1. Certificates ์ƒ์„ฑ

  • ์•„๊นŒ ๋งŒ๋“  Identifier ๋ฅผ ์„ ํƒํ•ด์„œ ํ•˜๋‹จ์˜ Push Notification ์—์„œ configure ๋ฅผ ํด๋ฆญํ•œ๋‹ค.

  • ์šฉ๋„์— ๋งž๊ฒŒ ์ธ์ฆ์„œ๋ฅผ ์ƒ์„ฑํ•˜๋ฉด ๋œ๋‹ค. (ํŒŒ์ด์–ด๋ฒ ์ด์Šค์—์„œ๋Š” Development ์™€ Production ๋ชจ๋‘ ์š”๊ตฌํ•œ๋‹ค.)

  • ์•„๊นŒ ๋งŒ๋“ค์–ด๋‘” CSR ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•œ๋‹ค.

  • ์ƒ์„ฑํ•œ ์ธ์ฆ์„œ๋ฅผ ๋‹ค์šด๋กœ๋“œํ•ด์ค€๋‹ค.

ํ™•์ธ)

๊ทธ๋Ÿฌ๋ฉด Account
โžก๏ธ
Certificates, IDs & Profiles
โžก๏ธ
Certificates ์—์„œ ์ƒ์„ฑํ•œ ์ธ์ฆ์„œ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

A-2. Certificate ๋ฅผ ํ‚ค์ฒด์ธ์— ๋“ฑ๋กํ•˜๊ธฐ

  • ๋‹ค์šด๋กœ๋“œ๋ฐ›์€ aps_development.cer ํŒŒ์ผ์„ ๋”๋ธ”ํด๋ฆญํ•ด์„œ ํ‚ค์ฒด์ธ์— ๋“ฑ๋กํ•ด์ค€๋‹ค.

(์ด๋•Œ ํ‚ค๋„ ๊ฐ™์ด ๋“ฑ๋ก๋˜๋Š”๋ฐ ํ•œ๋ฒˆ๋งŒ ๋“ฑ๋ก ํ•  ์ˆ˜ ์žˆ๋Š” ๋“ฏ ํ•˜๋‹ค. ๊ถ๊ธˆํ•ด์„œ ํ‚ค์ฒด์ธ์—์„œ ์‚ญ์ œํ•ด๋ดค๋Š”๋ฐ ํ‚ค๋Š” ๋“ฑ๋ก์ด ์•ˆ๋œ๋‹ค. identifier ๋ฅผ ์ƒˆ๋กœ ๋“ฑ๋กํ•ด์ฃผ๊ณ  ์ธ์ฆ์„œ๋„ ๋‹ค์‹œ ๋งŒ๋“ค์ž ๋“ฑ๋ก ํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.)

(์ผ๋ถ€ ๊ธ€์—์„œ p8 ํŒŒ์ผ์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„œ apple developer ์—์„œ key ๋ฅผ ๋“ฑ๋กํ•ด์ฃผ๋Š”๋ฐ ๊ทธ๋•Œ๋งŒ ๋‹ค์šด๋กœ๋“œ๊ฐ€ ๊ฐ€๋Šฅํ–ˆ๋‹ค. p12 ํŒŒ์ผ์— ๋Œ€ํ•ด์„œ ํ‚ค๋Š” ์ด๋•Œ๋งŒ ๋“ฑ๋ก๊ฐ€๋Šฅํ•œ ๊ฒƒ ๊ฐ™๋‹ค.)

A-3. p12 ํŒŒ์ผ ์ƒ์„ฑ

์šฐ๋ฆฌ๊ฐ€ Push Notification ์„ ๋ฐ›๊ธฐ ์œ„ํ•ด์„ ย ย pemย ํ˜•ํƒœ์˜ ์ธ์ฆ์„œ๊ฐ€ ํ•„์š”ํ•˜๋‹ค.(๊ฒฝ์šฐ์— ๋”ฐ๋ผ์„œ๋Š” p12 ํ˜•ํƒœ์˜ ํŒŒ์ผ๋งŒ ์š”๊ตฌ๋˜๊ธฐ๋„ ํ•œ๋‹ค.) ๊ทธ๋ ‡๊ธฐ ์œ„ํ•ด์„œ ๋จผ์ € p12 ํ˜•ํƒœ์˜ ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์•ผ ํ•˜๋Š”๋ฐ, ์ด p12 ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•ด์„ ย ์•„๊นŒ ํ‚ค์ฒด์ธ์— ๋“ฑ๋กํ–ˆ๋˜ย ์ธ์ฆ์„œ์™€ย ํ‚ค๊ฐ€ ํ•„์š”ํ•˜๋‹ค.

  • ํ‚ค์ฒด์ธ์„ ๋“ฑ๋กํ•  ๋•Œ ๋กœ์ปฌํ•ญ๋ชฉ์— ์ง€์ •ํ•ด๋‘์—ˆ๋‹ค๋ฉด ๊ธฐ๋ณธํ‚ค์ฒด์ธ – ๋กœ๊ทธ์ธ – ์ธ์ฆ์„œ ์—์„œ ์ธ์ฆ์„œ์™€ ๊ฐœ์ธํ‚ค๋ฅผ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ์ธ์ฆ์„œ์™€ ๊ฐœ์ธํ‚ค ๋‘๊ฐœ๋ชจ๋‘ ์„ ํƒํ•˜๊ณ  ๋‚ด๋ณด๋‚ด๊ธฐํ•œ๋‹ค.

  • .p12 ํŒŒ์ผ๋กœ ์„ค์ •ํ•˜๊ณ  ์ €์žฅํ•ด์ค€๋‹ค.

  • ์•”ํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ๋Š”๋ฐ ๋‚˜์ค‘์—๋„ ํ•„์š”ํ•˜๋‹ค ๊ธฐ์–ตํ•ด๋‘์ž.

*provider server ์— ์ธ์ฆ์„œ์™€ ๊ฐœ์ธ ํ‚ค๋ฅผ ๋ชจ๋‘ ์„ค์น˜ํ•ด์•ผํ•˜๋Š”๋ฐ, ์„œ๋ฒ„ ๊ฐœ๋ฐœํ™˜๊ฒฝ์— ๋”ฐ๋ผ ์ „๋‹ฌํ•  ํŒŒ์ผ์ด ๋‹ฌ๋ผ์ง„๋‹ค๊ณ  ํ•œ๋‹ค. php ์„œ๋ฒ„์—๋Š” .pem ์„ ์ „๋‹ฌํ•ด์•ผํ•˜๊ณ , ๋‚˜๋จธ์ง€๋Š” .p12 ๋งŒ ์ „๋‹ฌํ•ด๋„ ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋Š” ๋“ฏํ•˜๋‹ค.

firebase ๊ฐ™์€๊ฒฝ์šฐ๋Š” ๋‘๊ฐ€์ง€ ์ง€์›ํ•œ๋‹ค.

์ฐธ๊ณ ) pem ํŒŒ์ผ์ด ์š”๊ตฌ๋œ๋‹ค๋ฉด ์•„๋ž˜ ์ฃผ์†Œ๋ฅผ ์ฐธ์กฐํ•ด์„œ ํ†ตํ•ด์„œ ๋งŒ๋“ค์–ด์ฃผ๋ฉด ๋œ๋‹ค.

https://babbab2.tistory.com/57

B. p8 ์ธ์ฆํ‚ค ๋งŒ๋“ค๊ธฐ

์œ„์˜ App ID ๋“ฑ๋ก ๋ฐฉ๋ฒ•๊ณผ ๋˜‘๊ฐ™์ด ํ•ด์ฃผ๊ณ  ๋‹ค๋ฅธ์ ์€ Development ์™€ Production certificates ๋งŒ ๋งŒ๋“ค์ง€ ์•Š์œผ๋ฉด ๋œ๋‹ค. ์™œ๋ƒ๋ฉด ์šฐ๋ฆฐ ์ธ์ฆ์„œ๊ฐ€ ์•„๋‹Œ ์ธ์ฆํ‚ค๋ฅผ ์‚ฌ์šฉํ• ๊ฑฐ๋‹ˆ๊นŒ.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-06-17 แ„‹แ…ฉแ„’แ…ฎ 2 32 49

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-06-17 แ„‹แ…ฉแ„’แ…ฎ 2 33 04

๋…ธ๋ž€์ƒ‰ ๊ฒฝ๊ณ ์ฒ˜๋Ÿผ ํ•œ๋ฒˆ๋งŒ ๋‹ค์šด๋กœ๋“œ ๊ฐ€๋Šฅํ•˜๋‹ค.

๊ทธ ๋‹ค์Œ์€ ํŒŒ์ด์–ด๋ฒ ์ด์Šค์—์„œ p8 ํŒŒ์ผ์„ ์ธ์ฆํ‚ค๋กœ ๋“ฑ๋กํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

์ถœ์ฒ˜

[React Native]

๐Ÿ”ฅ
Firebase ๋กœ ํ‘ธ์‰ฌ ์•Œ๋ฆผ ๊ตฌํ˜„ํ•˜๊ธฐ – (2) iOS ์•ฑ์—์„œ ํ‘ธ์‹œ ์•Œ๋ฆผ ๋„์šฐ๊ธฐ!

3. ํ”„๋กœ์ ํŠธ์—์„œ iOS Push Notification, Backgrounds Mode ํ™œ์„ฑํ™”

  • ์ž์‹ ์˜ iPhone ์—์„œ ๋Œ๋ฆด ๊ฒฝ์šฐ์— ํ•ด๋‹น ๊ฐœ๋ฐœ์ž๊ณ„์ •๊ณผ device ๋ฅผ ์„ค์ •ํ•œ๋‹ค.
  • Signing & Capabilities ํƒญ์—์„œ +Capability ๋ฅผ ์„ ํƒํ•ด์„œ Push Notifications ๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.

  • ๊ฐ™์€ ๋ฐฉ๋ฒ•์œผ๋กœ Background Modes ๋„ ์ถ”๊ฐ€ํ•˜๊ณ  Background fetch ์™€ Remote notifications ๋ฅผ ์„ค์ •ํ•œ๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-06-16 แ„‹แ…ฉแ„’แ…ฎ 9 33 58

4. firebase ์—์„œ ํ‘ธ์‹œ ์•Œ๋ฆผ์„ ๊ตฌํ˜„ํ•œ๋‹ค๋ฉด?

  • p8 ํ‚ค๋ฅผ ์“ฐ๋Š” ์˜ˆ์‹œ. ์ธ์ฆํ‚ค๋Š” 1๋…„๋งˆ๋‹ค ๊ฐฑ์‹ ํ•˜์ง€ ์•Š์•„๋„ ๋˜๊ธฐ ๋•Œ๋ฌธ์— ๋ณดํ†ต p8 ๋ฅผ ์“ฐ๋Š” ์˜ˆ์‹œ๊ฐ€ ๋งŽ์•˜๋‹ค.

https://velog.io/@mayinjanuary/React-Native-Firebase-๋กœ-ํ‘ธ์‰ฌ-์•Œ๋ฆผ-๊ตฌํ˜„ํ•˜๊ธฐ-2-IOS-์•ฑ-์„ธํŒ…ํ•˜๊ธฐ

  • p12 ์ธ์ฆ์„œ๋ฅผ ์“ฐ๋Š” ์˜ˆ์‹œ. ์ธ์ฆ์„œ๋Š” 1๋…„๋งˆ๋‹ค ๊ฐฑ์‹ ํ•ด์•ผ ํ•œ๋‹ค.

https://faith-developer.tistory.com/156

์ž ์‹ค์ œ๋กœ ํ•œ๋ฒˆ ํ‘ธ์‹œ์•Œ๋ฆผ์„ ๋ณด๋‚ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

5. iOS ์•ฑ์— Firebase ์ถ”๊ฐ€ํ•˜๊ธฐ

iOS ์•ฑ์„ ๋‚ด Firebase ํ”„๋กœ์ ํŠธ์™€ ์•ˆ์ „ํ•˜๊ฒŒ ์—ฐ๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„ , ์ธ์ฆ์„œ ํŒŒ์ผ์„ ๋‹ค์šด๋ฐ›์•„์•ผ ํ•˜๊ณ , ๊ทธ๊ฑธ ๋‚ด iOS ์•ฑ ์•ˆ์— ์„ธํŒ…ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  • ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•ด์ฃผ๊ณ 
  • ios ์•ฑ์„ ์ถ”๊ฐ€ํ•ด์ค๋‹ˆ๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-06-19 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 1 17 00

  • ์•ฑ์„ ๋“ฑ๋กํ•ด์ค๋‹ˆ๋‹ค. (iOS ๋ฒˆ๋“ค ID ๋Š” ํ”„๋กœ์ ํŠธํŒŒ์ผ์—์„œ ํ™•์ธ๊ฐ€๋Šฅํ•˜๋‹ค.)

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-06-19 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 1 18 36

  • GoogleService-info.plist ๋‹ค์šด๋กœ๋“œ ํ•ด์„œ ํ”„๋กœ์ ํŠธ์— ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-06-19 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 9 41 10

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-06-19 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 9 41 37

  • Friebase SDK ๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-06-19 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 9 45 15

  • ์ถ”๊ฐ€์ ์œผ๋กœ ์ถ”ํ›„์— ๋ฉ”์‹œ์ง€ ์ˆ˜์‹ ์„ ์œ„ํ•ด์„œ Firebase/Messaging ํ•„์š”ํ•˜๋‹ˆ ์ง€๊ธˆ ๊ฐ™์ด ์ถ”๊ฐ€ํ•ด์„œ install ํ•ด์ฃผ์ž.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-06-19 แ„‹แ…ฉแ„’แ…ฎ 2 30 23

  • AppDelegate.swift ํŒŒ์ผ์— import Firebase ์™€ FirebaseApp.configure() ๋ฅผ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-06-19 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 9 46 57

6. ์•Œ๋ฆผ ๊ถŒํ•œ ์š”์ฒญ

  • iOS ์—์„œ๋Š” ์‚ฌ์šฉ์ž์˜ ๋™์˜ ์—†๋Š” notification ์„ ์ˆ˜์‹ ํ•˜์ง€ ๋ชปํ•˜๋„๋ก ํ–ˆ๊ธฐ๋•Œ๋ฌธ์— ๊ถŒํ•œ์„ ์š”์ฒญํ•ด์•ผํ•œ๋‹ค.

๋ณดํ†ต ์•ฑ์ด ์ฒ˜์Œ ์‹คํ–‰๋  ๋•Œ ๋ฌผ์–ด๋ณด๊ฑฐ๋‚˜ ํ‘ธ์‹œ์•Œ๋ฆผ์„ ์„ค์ •ํ•˜๋Š” ๋‹จ๊ณ„์—์„œ ๋ฌผ์–ด๋ณด๋ฉด ๋œ๋‹ค. ์•„๋ž˜ ์ฝ”๋“œ๋Š” ์•ฑ์„ ๋Ÿฐ์น˜ํ•  ๋•Œ ๊ถŒํ•œ์„ ์š”์ฒญํ•˜๊ธฐ ์œ„ํ•ด์„œ application(_:didFinishLaunchingWithOptions:) ๋ฉ”์„œ๋“œ์— ์ถ”๊ฐ€ํ•ด ์คฌ๋‹ค.

  • AppDelegate.swift

UNAuthorizationOptions ์œผ๋กœ ํ‘ธ์‹œ ๊ถŒํ•œ์„ ์„ค์ •ํ•ด์ค€๋‹ค. (alert : ์•Œ๋žŒ ๊ถŒํ•œ, badge : badge ์—…๋ฐ์ดํŠธ ๊ถŒํ•œ, sound : ์†Œ๋ฆฌ ๊ถŒํ•œ)

Bool {
// Override point for customization after application launch.

// ๊ธฐ์กด์— ์ ์—ˆ๋˜ ํŒŒ์ด์–ด๋ฒ ์ด์Šค ๊ถŒํ•œ ์„ค์ •
FirebaseApp.configure()

// ํ‘ธ์‹œ ๊ถŒํ•œ ์„ค์ •
UNUserNotificationCenter.current().delegate = self

let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter
.current()
.requestAuthorization(
options: authOptions,completionHandler: { (_, _) in }
)
application.registerForRemoteNotifications()

return true
}
“>

// Tells the delegate that the launch process is almost done and the app is almost ready to run.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

	// ๊ธฐ์กด์— ์ ์—ˆ๋˜ ํŒŒ์ด์–ด๋ฒ ์ด์Šค ๊ถŒํ•œ ์„ค์ •
        FirebaseApp.configure()
        
	// ํ‘ธ์‹œ ๊ถŒํ•œ ์„ค์ •
        UNUserNotificationCenter.current().delegate = self

        let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter
          .current()
          .requestAuthorization(
            options: authOptions,completionHandler: { (_, _) in }
          )
        application.registerForRemoteNotifications()
        
        return true
    }
  • ํŒŒ์ด์–ด๋ฒ ์ด์Šค์˜ ๋…ธํ‹ฐ๊ฐ€ ์ˆ˜์‹ ๋  ์ˆ˜ ์žˆ๋„๋ก ํ•œ๋‹ค.
Void) {
completionHandler([.alert, .sound])
}

// 2. Asks the delegate to process the user’s response to a delivered notification.
func userNotificationCenter(_ center: UNUserNotificationCenter,didReceive response: UNNotificationResponse,withCompletionHandler completionHandler: @escaping () -> Void) {
completionHandler()
}
}
“>

extension AppDelegate : UNUserNotificationCenterDelegate {
	
	// 1. Asks the delegate how to handle a notification that arrived while the app was running in the foreground.
    func userNotificationCenter(_ center: UNUserNotificationCenter,willPresent notification: UNNotification,withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        completionHandler([.alert, .sound])
    }

	// 2. Asks the delegate to process the user's response to a delivered notification.
    func userNotificationCenter(_ center: UNUserNotificationCenter,didReceive response: UNNotificationResponse,withCompletionHandler completionHandler: @escaping () -> Void) {
        completionHandler()
    }
}

์ฃผ์„)

1 : userNotificationCenter(_:willPresent:withCompletionHandler:) ๋ฉ”์„œ๋“œ๋Š” foreground ์—์„œ ๋Ÿฌ๋‹์ค‘์— ์•ฑ์— ๋„์ฐฉํ•˜๋Š” notification ์„ ๋‹ค๋ฃฌ๋‹ค.

completionHandler() ์€ notification ์— ๋Œ€ํ•ด์„œ presentation option ์„ ๊ฐ€์ง€๊ณ  ์‹คํ–‰๋  ๋ธ”๋ก์ด๋‹ค. UNNotificationPresentationOptions(.sound, .badge ๋“ฑ์˜ ์˜ต์…˜) -> Void ์„ ํ†ตํ•ด ์ด ๋ธ”๋ก์—๋Š” ๋ฆฌํ„ด๊ฐ’์ด ์—†๊ณ  UNNotificationPresentationOptions ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์‚ฌ์šฉํ•จ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

2 : userNotificationCenter(_:didReceive:withCompletionHandler:) ๋ฉ”์„œ๋“œ๋Š” ๋„์ฐฉํ•œ notification ์— ๋Œ€ํ•œ user ์˜ ๋ฐ˜์‘์„ ๋‹ค๋ฃฌ๋‹ค.

completionHandler ์˜ ๋ฐ˜ํ™˜๊ฐ’์ด () -> Void completionHandler() ์ด๊ธฐ ๋•Œ๋ฌธ์— completionHandler ๋งˆ์ง€๋ง‰์— ํ•ญ์ƒ completionHandler() ๋ฅผ ํ˜ธ์ถœํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.

์ด ๋ฉ”์„œ๋“œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด notification ์—์„œ action ์— ๋Œ€ํ•œ ์„ค์ •์„ ํ•  ์ˆ˜ ์žˆ๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-06-19 แ„‹แ…ฉแ„’แ…ฎ 10 03 35

๋” ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์•„๋ž˜ ์ฃผ์†Œ๋ฅผ ์ฐธ์กฐ.

Apple Developer – Declaring Your Actionable Notification Types


warning

iOS 14.0 ์—์„œ alert ์˜ต์…˜์ด ์ถ”์ฒœ๋˜์ง€ ์•Š์•˜๋‹ค. ๊ทธ๋ž˜์„œ UNNotificationPresentationOptions ์— ์–ด๋–ค ์†์„ฑ๋“ค์ด ์กด์žฌํ•˜๋Š”์ง€ ์‚ดํŽด๋ณด์•˜๋‹ค.

_2021-06-19__2 41 56

_2021-06-19__2 41 28

badge : ์•ฑ ์•„์ด์ฝ˜ ์šฐ์ธก์ƒ๋‹จ์— ํ‘œ์‹œ๋˜๋Š” ์•Œ๋ฆผ ์ˆซ์ž๊ฐ€ badge ์— ํ•ด๋‹นํ•œ๋‹ค. foreground ์ผ ๊ฒฝ์šฐ๋Š” ์•Œ๋ฆผ์„ ๋ฐ”๋กœ ํ™•์ธํ•˜๋‹ˆ๊นŒ ํŠน๋ณ„ํ•œ ๊ฒฝ์šฑ ์•„๋‹ˆ๋ฉด ๋ถˆํ•„์š”ํ•˜๋‹ค.

sound : notification ๊ณผ ๊ด€๋ จ๋˜ ์†Œ๋ฆฌ๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.

alert : notification ์œผ๋กœ๋ถ€ํ„ฐ content ๋ฅผ ์ œ๊ณต๋ฐ›์•„ alert ์•Œ๋žŒ์„ ๋ณด์—ฌ์ค€๋‹ค.

iOS 14 ๋ถ€ํ„ฐ ์ถ”๊ฐ€๋œ ์˜ต์…˜๋“ค์ด๋‹ค. alert ๋Š” ๋”์ด์ƒ ์ถ”์ฒœ๋˜์ง€ ์•Š๋Š”๋‹ค.

banner : ๋ฐฐ๋„ˆ์ฒ˜๋Ÿฌ notification ์„ ๋ณด์—ฌ์ค€๋‹ค.

list : Notification Center ์—์„œ ๋ณด์—ฌ์ค€๋‹ค. (๋ง ๊ทธ๋Œ€๋กœ ์•Œ๋ฆผ์„ผํ„ฐ๋‹ค. ์ž ๊ธˆ ํ™”๋ฉด์—์„œ ํ™”๋ฉด์˜ ์ค‘๊ฐ„์„ ์Šค์™€์ดํ”„ ์—…ํ•˜๊ฑฐ๋‚˜ ๋‹ค๋ฅธ ํ™”๋ฉด์—์„œ ์Šคํฌ๋ฆฐ ์œ„์˜ ์ค‘์•™์„ ์Šค์™€์ดํ”„๋‹ค์šดํ•˜๋ฉด ๋‚˜์˜ค๋Š” ‘์•Œ๋ฆผ์„ผํ„ฐ’๋‹ค.)

  • ์•ฑ์„ ์‹คํ–‰ํ•˜๊ฒŒ ๋˜๋ฉด notifications ์— ๋Œ€ํ•œ ๊ถŒํ•œ์„ ์š”์ฒญํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์•ฑ์„ค์ €์—์„œ ํ™•์ธํ•ด๋ณด๋ฉด Allow Notificiations ๊ฐ€ ์„ค์ •๋˜์–ด์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ๋‹ค.

7. Firebase iOS ์•ฑ ๋‚ด์— ์ธ์ฆ์„œ ๋“ฑ๋ก

  • ํŒŒ์ด์–ด๋ฒ ์ด์Šค์— ๋“ฑ๋กํ–ˆ๋˜ ํ”„๋กœ์ ํŠธ์˜ ์•ฑ์„ ์„ ํƒํ•œ๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-06-19 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 9 59 57

  • ํด๋ผ์šฐ๋“œ ๋ฉ”์‹œ์ง•์—์„œ ์ธ์ฆ์„œ๋ฅผ ๋“ฑ๋กํ•œ๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-06-19 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 10 00 53

  • ์ธ์ฆํ‚ค ์ฆ‰ p8 ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜๋ฉด ์ข‹๋‹ค๊ณ  ํ•˜์ง€๋งŒ ๋‚˜๋Š” p12 ํŒŒ์ผ๋งŒ ์žˆ๊ธฐ๋•Œ๋ฌธ์— APN ์ธ์ฆ์„œ์— ์ธ์ฆ์„œ๋ฅผ ์—…๋กœ๋“œ ํ•  ๊ฒƒ์ด๋‹ค.

A-1. Certificates ์ƒ์„ฑ ๋‹จ๊ณ„์—์„œ ๊ฐœ๋ฐœ APN ๊ณผ ํ”„๋กœ๋•์…˜ APN ์„ ๋งŒ๋“ค์–ด์ฃผ๋ฉด ๋œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ํ‚ค์ฒด์ธ์—์„œ ๋‚ด๋ณด๋‚ด๊ธฐํ•œ p12 ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•ด์ค€๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-06-19 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 10 06 04

8. Firebase ์ฝ˜์†”์—์„œ ํ…Œ์ŠคํŠธ ๋ฉ”์„ธ์ง€ ๋ณด๋‚ด๊ธฐ

  • Cloud Messaging ๋“ค์–ด๊ฐ„๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-06-19 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 10 11 24

  • ๋ฉ”์‹œ์ง€ ๋ณด๋‚ด๊ธฐ

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-06-19 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 10 13 27

  • ์•Œ๋ฆผ ์ œ๋ชฉ๊ณผ ํ…์ŠคํŠธ๋ฅผ ์„ค์ •ํ•ด์ค€๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-06-19 แ„‹แ…ฉแ„’แ…ฎ 3 08 54

  • ํŒŒ์ด์–ด๋ฒ ์ด์Šค์— ๋“ฑ๋กํ•œ App ์„ ์„ ํƒํ•œ๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-06-19 แ„‹แ…ฉแ„’แ…ฎ 3 10 50

  • ์˜ˆ์•ฝํ•  ์˜ต์…˜์„ ์„ ํƒํ•˜๊ณ  ๋‹ค์Œ์„ ๋ˆŒ๋Ÿฌ ์ง„ํ–‰์„ ํ•ด๋„ ๋˜๊ณ  ๊ฒ€ํ† ๋ฅผ ํ•ด๋„ ๋œ๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-06-19 แ„‹แ…ฉแ„’แ…ฎ 3 12 51

  • ๊ฒ€ํ† ํ•˜๊ฒŒ๋˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํŒ์—…์ฐฝ์ด ๋œฌ๋‹ค. ๊ฒŒ์‹œํ•ด๋ณด์ž.

_2021-06-19__3 14 09

์•„๋ž˜์˜ ์„ธ๊ฐ€์ง€ ๊ฒฝ์šฐ ๋ชจ๋‘ ์ •์ƒ์ ์œผ๋กœ ๋„์ฐฉํ•œ๋‹ค๋ฉด ํ…Œ์ŠคํŠธ ๋ฉ”์‹œ์ง€ ๋ณด๋‚ด๊ธฐ ์„ฑ๊ณต์ด๋‹ค.

  • ์•ฑ์ด ์ผœ์ ธ์žˆ์„ ๋•Œ (Foreground)
  • ์•ฑ์ด ์ผœ์ ธ์žˆ์ง€๋งŒ background ์— ์žˆ์„ ๋•Œ (Background)
  • ์•ฑ์ด ๊บผ์ ธ์žˆ์„ ๋•Œ (Quit)

GitHub

https://github.com/hyun99999/APNsTutorial-iOS