WWDC22) Hello Swift Charts

2 minute read

๐Ÿ‘‰ Overview

์‹œ๋ฎฌ๋ ˆ์ดํ„ฐ์—์„œ dynamic interface ๋ฅผ ํ…Œ์ŠคํŠธ ํ•  ์ค€๋น„๊ฐ€ ๋˜๋ฉด, notification interface ๋ฅผ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•œ custom build scheme ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. scheme ๋ฅผ ๊ตฌ์„ฑํ•˜๊ธฐ ์œ„ํ•ด์„œ test data ๊ฐ€ ํฌํ•จ๋œ JSON ๋ฐ์ดํ„ฐ ํŒŒ์ผ์„ ์ง€์ •ํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๊ธฐ ์œ„ํ•ด์„œ PushNotificationPayload.apns ํŒŒ์ผ์„ ์ ์ ˆํ•˜๊ฒŒ ์ˆ˜์ •ํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.. ์—ฌ๊ธฐ์—๋Š” remote notification ์„ ์‹œ๋ฎฌ๋ ˆ์ด์…˜ํ•˜๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ํ‚ค๊ฐ€ ๋“ค์–ด์žˆ์Šต๋‹ˆ๋‹ค. ๐Ÿ‘‰ Add a Scheme

notification ์„ ์•ฑ์— ์ถ”๊ฐ€ํ•  ๋•Œ ํ…Œ์ŠคํŠธํ•  scheme ๋„ ์ถ”๊ฐ€ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ๊ฐ€์ง€ category ์˜ notification ์„ ํ…Œ์ŠคํŠธํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ฐ category ์— ๋Œ€ํ•œ scheme ๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

1

Edit Sheme > Run ์—์„œ Watch Interface ๋ฅผ Dynamic Notification ์œผ๋กœ ์„ค์ •ํ•˜๊ณ , Notification Playload ๋ฅผ ์„ค์ •ํ•ด์ค๋‹ˆ๋‹ค.

2

notification scheme ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ํ•ด๋‹น payload ๊ฐ€ ์›Œ์น˜๋กœ ์ „์†ก๋ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ, payload ํŒŒ์ผ์„ ์•„์ดํฐ, ์• ํ”Œ ์›Œ์น˜ ์‹œ๋ฎฌ๋ ˆ์ดํ„ฐ๋กœ ๋Œ์–ด๋†“์•„์„œ notification ์„ ํŠธ๋ฆฌ๊ฑฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด ๊ฒฝ์šฐ์—๋Š” Simulator Target Bundle ์„ target ์˜ bundle ID ๋กœ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ, ํ•ด๋‹น ๊ธฐ๊ธฐ๊ฐ€ ์•Œ๋ฆผ์„ ์ˆ˜์‹ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ถŒํ•œ์ด ์ด๋ฏธ ์š”์ฒญ๋˜์–ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๋งˆ์ง€๋ง‰์œผ๋กœ, ์ฆ‰์‹œ ์ „๋‹ฌ๋˜๋Š” ๊ฒƒ์€ ์•„๋‹™๋‹ˆ๋‹ค. ์ตœ๋Œ€ 1๋ถ„์ด ์ง€์—ฐ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

To add a new payload file:

3

์ด๋ฅผ ํ†ตํ•ด ํ”„๋กœ์ ํŠธ์— ์—ฌ๋Ÿฌ payload ํŒŒ์ผ์„ ํฌํ•จํ•˜๊ณ , build scheme ๋ฅผ ๋ณ€๊ฒฝํ•˜๋ฉด์„œ ํ…Œ์ŠคํŠธ๋ฅผ ๋‹จ์ˆœํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ‘‰ Edit the JSON Payload

payload ํŒŒ์ผ์„ ์ˆ˜์ •ํ•ด์„œ ์‹ค์ œ์ ์œผ๋กœ ์•ฑ์— ์ „๋‹ฌ๋˜๋Š” notification content ์™€ ์ผ์น˜์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ Apple Developer - Generating a remote notification ์„ ์ฐธ์กฐํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

payload ํŒŒ์ผ์—๋Š” WatchKit Simulator Actions key ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ํ‚ค๋Š” ์ผ๋ฐ˜ notificationโ€™s payload ์˜ ์ผ๋ถ€๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค. ๊ฐ action button ์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

๋‹ค์Œ์˜ ํ‚ค๊ฐ€ ํฌํ•จ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

title (Required) action button ์˜ ์ œ๋ชฉ์ž…๋‹ˆ๋‹ค. identifier (Required) ์‚ฌ์šฉ์ž๊ฐ€ ์„ ํƒํ•œ action ์„ ์‹๋ณ„ํ•˜๋Š” ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž๊ฐ€ ๋ฒ„ํŠผ์„ ํƒญํ•˜๋ฉด, ์‹œ์Šคํ…œ์€ notification center delegate ์˜ userNotificationCenter(_:didReceive:withCompletionHandler:) ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค. ์‹œ์Šคํ…œ์€ ์ด ํ‚ค์˜ ๊ฐ’์„ ์ด ๋ฉ”์†Œ๋“œ์— ์ „๋‹ฌ๋œ UNNotificationResponse ๊ฐ์ฒด์˜ actionIdentifier ํ”„๋กœํผํ‹ฐ ์— ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. behavior (Optional) ์ด ํ‚ค์˜ ์œ ์ผํ•œ ๊ฐ’์€ ๋ฌธ์ž์—ด textInput ์ž…๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์ด ํ‚ค๊ฐ€ ์žˆ๋‹ค๋ฉด, resulting button ์ด text input ์„ ํŠธ๋ฆฌ๊ฑฐ ํ•ฉ๋‹ˆ๋‹ค. destructive (Optional) ๊ฐ’ 1 ๋˜๋Š” 0, ์—ฌ๊ธฐ์„œ 1์€ resulting button ์ด destructive action ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๊ฒƒ์„ ๋‚˜ํƒ€๋‚ด๋Š” ๋ฐฉ์‹์œผ๋กœ ๋ Œ๋”๋ง ๋ฉ๋‹ˆ๋‹ค. ๊ฐ’์ด 0์ด๋ฉด ์ •์ƒ์ ์œผ๋กœ ๋ Œ๋”๋ง๋ฉ๋‹ˆ๋‹ค. background (Optional) ๊ฐ’ 1 ๋˜๋Š” 0, ์—ฌ๊ธฐ์„œ 1์€ ๋ฒ„ํŠผ์ด ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ์•ฑ์„ ์‹คํ–‰ํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. ๐Ÿ‘‰ Send Test Notifications to the Watch

์‹œ์Šคํ…œ์ด ์• ํ”Œ ์›Œ์น˜์— notification ์„ ์ „๋‹ฌํ• ์ง€ ์—ฌ๋ถ€๋ฅผ ์ž๋™์œผ๋กœ ๊ฒฐ์ •ํ•˜๊ธฐ ๋•Œ๋ฌธ์—(์• ํ”Œ์›Œ์น˜๋ฅผ ์ฐฉ์šฉํ•˜๊ฒŒ ๋˜๋ฉด ์ž๋™์œผ๋กœ ์ „๋‹ฌ๋œ๋‹ค.) ๊ธฐ๊ธฐ์—์„œ ํ…Œ์ŠคํŠธํ•  ๋•Œ ์‹œ์Šคํ…œ์ด ์˜ˆ์ƒ๋Œ€๋กœ notification ์„ ์• ํ”Œ์›Œ์น˜๋กœ ๋ผ์šฐํŒ…ํ•˜๋„๋ก ๊ธฐ๊ธฐ์˜ ์ƒํƒœ๋ฅผ ์„ค์ •ํ•ด์•ผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ธฐ๊ธฐ๋ฅผ ์†๋ชฉ์— ์ฐฉ์šฉํ•˜์ง€ ์•Š์€ ์ƒํƒœ์—์„œ notification interfaces ๋ฅผ ํ…Œ์ŠคํŠธํ•˜๋ ค๋ฉด ๋‹ค์Œ์˜ ๋‹จ๊ณ„๋ฅผ ๋”ฐ๋ฅด์„ธ์š”.

์• ํ”Œ ์›Œ์น˜์—์„œ ์†๋ชฉ ๊ฐ์ง€๋ฅผ ๋น„ํ™œ์„ฑํ™” ํ•ฉ๋‹ˆ๋‹ค. companion iPhone ์˜ watch ์•ฑ ๋˜๋Š” watch ์˜ Setting ์—์„œ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ต์…˜์€ Passcode > Wrist Detection ์— ์žˆ์Šต๋‹ˆ๋‹ค. ์• ํ”Œ ์›Œ์น˜๊ฐ€ ์ถฉ์ „๊ธฐ์— ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์ง€ ์•Š์€์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. iPhone ์„ ์ž ๊ทธ์„ธ์š”. ๐Ÿ’ซ ํ…Œ์ŠคํŠธ๋ฅผ ํ•ด๋ด…์‹œ๋‹ค!

watch ์—์„œ ๋นŒ๋“œํ•˜๊ฒŒ ๋˜๋ฉด ์•Œ๋ฆผ ๊ถŒํ•œ์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์š”์ฒญํ•ฉ๋‹ˆ๋‹ค.

๋ฐ”๋กœ ์•Œ๋ฆผ์ด ์˜ค๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

์ง 

โ“ Simulator Target Bundle

์ถ”๊ฐ€์ ์œผ๋กœ, ๋นŒ๋“œํ•  ๋•Œ ๋งˆ๋‹ค ๋ง๊ณ , ์•ž์„œ ์‚ดํŽด๋ณธ ๊ฒƒ์ฒ˜๋Ÿผ apns ํŒŒ์ผ์„ ๊ธฐ๊ธฐ์— ๋Œ์–ด ๋†“์•„์„œ ๋ฐ›์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

์ด๋•Œ, ๊ทธ๋ƒฅ ์ง‘์–ด๋„ฃ๊ฒŒ ๋˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋‚˜์˜ต๋‹ˆ๋‹ค.

7

ํ•ด๋‹น target ์˜ bundle identifier ๋ฅผ apns ํŒŒ์ผ์— Simulator Target Bundle key ๋กœ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

Categories:

Updated: