(iOS) background/foreground, RemoteNotification ๊ตฌ๋ณ„ํ•˜๊ธฐ

Oct 15, 2013/Apr 24, 2017

์ œ๋ชฉ์ด ์ข€ ๋‚œ๊ฐํ•œ๋ฐ;; ์ƒํ™ฉ์€ ์ด๋ ‡๊ฒŒ Remote Notification์€ ๋ง ๊ทธ๋Œ€๋กœ ์›๊ฒฉ์ง€์—์„œ ์•Œ๋žŒ์ด ์˜ค๋Š”๊ฒƒ์ธ๋ฐ ์• ํ”Œ์˜ ๊ฒฝ์šฐ APNS๋ฅผ ํ†ตํ•ด์„œ ์ด๋ฃจ์–ด ์ง€๋Š”๋ฐ, ์•ฑ์˜ ์ž…์žฅ์—์„œ ๋ณด๋ฉด Remote Notification ์„ ๋ฐ›๋Š” 2๊ฐ€์ง€ ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค.ย 

1. ์•ฑ์ด ์ผœ์ ธ ์žˆ๋Š” ์ƒํƒœ์—์„œ Remote Notification์ด ์˜ค๋Š” ๊ฒฝ์šฐ(foreground)

2. ์•ฑ์ด ๊บผ์ ธ ์žˆ๋Š” ์ƒํƒœ์—์„œ Remote Notification์ด ์˜ค๋Š” ๊ฒฝ์šฐ(background)

์ด ๋‘๊ฒฝ์šฐ๊ฐ€ย ๊ฐ€์žฅ ํฐ ๋‹ค๋ฅธ์ ์€ย ์•ฑ์ด foreground ์— ์žˆ๋Š” 1๋ฒˆ์˜ ๊ฒฝ์šฐ, ์‚ดํŽด๋ณด๋ฉด ์•Œ๋ฆผ์ด ์˜ค๊ธด ํ•˜์ง€๋งŒ ํŒ์—…์ด๋‚˜ ํ™”๋ฉด ์ƒ๋‹จ์˜ ํ‘œ์‹œ๋˜์—ˆ๋‹ค๊ฐ€ ๋“ค์–ด๊ฐ€๋Š” ์‹์œผ๋กœ ๋™์ž‘ํ•˜์ง€ ์•Š๋Š”๋‹ค. ๋ผ์ธ(Line) ์˜ ๊ฒฝ์šฐ ๋‹ค๋ฅธ ์ฑ„ํŒ…์ฐฝ์— ์žˆ๋Š” ๊ฒฝ์šฐ back๋ฒ„ํŠผ์— (1) ์ด๋Ÿฐ์‹์œผ๋กœ ํ‘œ์‹œ๊ฐ€ ๋œ๋‹ค. ๋‹น์—ฐํžˆ background ์—์„œ๋Š” ํŒ์—…์ด๋‚˜ ์ƒ๋‹จ ํ‘œ์‹œ๊ฐ€ ๋œ๋‹ค. ย ๋˜ํ•˜๋‚˜์˜ ๋‹ค๋ฅธ ์ ์€ ์•ฑ์ด foreground์— ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์•Œ๋ฆผ์„ ์œ„ํ•œ json ์—์„œ ์ง€์ •ํ•œ sound๊ฐ€ ๋ฐœ์ƒ๋˜์ง€ ์•Š๋Š”๋‹ค. ์ด๋•Œ๋Š” foreground ์•ฑ์—์„œ ๋”ฐ๋กœ ํ•„์š”ํ•˜๋‹ค๋ฉด sound๋ฅผ ์žฌ์ƒํ•ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค.ย 

๊ทธ๋Ÿฐ๋ฐ background ์—์„œ ์•Œ๋ฆผ์ด ์™”๊ณ  ์‚ฌ์šฉ์ž๊ฐ€ ํ„ฐ์น˜๋ฅผ ํ•˜๋ฉด ์•ฑ์ด ์ผœ์ง€๋Š”๋ฐ ์ด ์ƒํƒœ์—์„œ ์•ฑ์ด Remote Notification ์„ ๋ฐ›๋Š” delegate๋Š” ์•„๋ž˜์™€ ๊ฐ™์€๋ฐ foreground ์—์„œ๋„ ์•„๋ž˜์˜ ๋ฉ”์†Œ๋“œ์— ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์•ผํ•œ๋‹ค.ย 

โ€“ (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

๊ทธ๋Ÿฌ๋‹ค ๋ณด๋‹ˆ ์ด๋Ÿฐ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธด๋‹ค. ์˜ˆ๋ฅผ๋“ค๋ฉด, Remote Notification ์ด ์™”์„๋•Œ ์–ด๋–ค ์†Œ๋ฆฌ๋ฅผ ์žฌ์ƒํ•ด์ค˜์•ผ ํ•œ๋‹ค๊ณ  ํ• ๋•Œ json ์˜ย  sound ์ง€์ •๋œ๊ฒƒ์„ iOSย  ์—์„œ ์žฌ์ƒ์ด ๋˜๊ณ , foreground ์—์„œ๋Š” iOS ๊ฐ€ json์˜ sound์—์„œ ์žฌ์ƒํ•ด์ฃผ์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— sound๋ฅผ ๋”ฐ๋กœ ์žฌ์ƒ์„ ํ•ด์ฃผ๋Š”๋ฐ ๋ฌธ์ œ๋Š” background ์—์„œ ์•Œ๋ฆผ์ด์™€์„œ ๋ˆŒ๋Ÿฌ์„œ ๋“ค์–ด๊ฐˆ๋•Œ๋„ ์ด sound๊ฐ€ ๋‹ค์‹œ ์žฌ์ƒ์ด ๋œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.ย 

๊ทธ๋ž˜์„œ ์ค‘์š”ํ•œ ๋ถ€๋ถ„์€ background ์—์„œ ์•Œ๋ฆผ์ด ์™”์„๋•Œ ์‚ฌ์šฉ์ž๊ฐ€ ์•Œ๋ฆผ์„ ๋ˆŒ๋Ÿฌ์„œ ์•ฑ์— ๋“ค์–ด์™€์„œ ์•Œ๋ฆผ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒฝ์šฐ์™€ foreground ์—์„œ ์•Œ๋ฆผ์ด ์™€์„œ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒฝ์šฐ๋ฅผ ๊ตฌ๋ณ„ํ•ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค. ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ๋ณด์ž.

ํฌ๊ฒŒ ๋‹ค๋ฅธ๊ฒƒ์€ ์—†๋Š”๋ฐ ์ค‘์š”ํ•œ ๋ถ€๋ถ„์€ ์•ฑ์ด background ์— ์žˆ๊ฑฐ๋‚˜ ์ข…๋ฃŒ๋˜์—ˆ๋‹ค๊ฐ€ ์‹คํ–‰๋˜๋Š” ๊ฒฝ์šฐ์—๋Š”, UIApplication ์˜ applicationState ๊ฐ€ UIApplciationStateInActive ์ƒํƒœ๋ผ๋Š” ๊ฒƒ์ด๊ณ  foreground ๋Š” ๋‹น์—ฐํžˆ UIApplciationStateActive ์ƒํƒœ๋ผ๋Š” ๊ฒƒ์ด ๊ฐ€์žฅ ํฐ ์ฐจ์ด๋‹ค. ๊ทธ๋ž˜์„œ ํ•ด๋‹น ๋ฉ”์†Œ๋“œ์—์„œ application.applicationState ๋กœ ๊ตฌ๋ถ„ํ•ด ์ฃผ๋ฉด ๋œ๋‹ค.ย 

๋‹ค๋ฅธ ๊ฒฝ์šฐ ๊ฐ€ ์ข€๋” ์žˆ์„์ง€ ๋ชจ๋ฅด๊ฒ ๋Š”๋ฐ, ์ผ๋‹จ์€ ์•ฑ์˜ applicationState ๋ฅผ ์ด์šฉํ•ด์„œ ์ฒ˜๋ฆฌํ• ์ˆ˜ ์žˆ์—ˆ๋‹ค. ๋ณด๋‹ค ์ข‹์€ ๋ฐฉ๋ฒ•์ด๋‚˜ ๋‹ค๋ฅธ ๊ฒฝ์šฐ๊ฐ€ ์žˆ์œผ๋ฉด ๋Œ“๊ธ€๋‹ฌ์•„ ์ฃผ์‹œ๊ธธ. ์•„๋‹ˆ๋ฉด ์œ„์˜ gist๋ฅผ ์ˆ˜์ •ํ•ด ์ฃผ์‹œ๋Š” ๊ฒƒ๋„ ํ•˜๋‚˜์˜ ๋ฐฉ๋ฒ•์ผ๋“ฏ.^^


#Background  #dev  #foreground  #IOS  #Remote Notification  #๋ฐฑ๊ทธ๋ผ์šด๋“œ  #ํฌ๊ทธ๋ผ์šด๋“œ