iOS

๋‚ด๊ฐ€ ํ•„์š”ํ•ด์„œ ๋งŒ๋“ค์–ด๋ณด๋Š” ์• ํ”Œ์›Œ์น˜ ์•ฑ (2)

๊ธฐ๊ฐ€์ •ํ›ˆ 2024. 1. 17. 17:46

์ž‘๋…„ 10์›”์— ๊ฐ„๋‹จํ•˜๊ฒŒ UI ๊ทธ๋ฆฌ๋Š” ๊ฒƒ์œผ๋กœ ์‹œ์ž‘ํ•˜๊ณ  ์˜ค๋žœ๋งŒ์— ์‹œ๊ฐ„์ด ์ž ๊น ์—ฌ์œ ๊ฐ€ ๋ผ์„œ ์ž‘์—…์„ ํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค.

์˜ค๋žœ๋งŒ์— ์ฝ”๋“œ๋ฅผ ๋ณด๋‹ˆ ๋ถ€๋ถ„๋งŒ ๊ธฐ์–ต์ด ๋‚˜์„œ ๋‹ค์‹œ ํ•œ๋ฒˆ ๋‚ด๊ฐ€ ๋งŒ๋“ค์—ˆ๋˜ ์ฝ”๋“œ๋ฅผ ์ ๊ฒ€ํ•˜๊ณ  ๊ณฐ๊ณฐ์ด ์ƒ๊ฐํ•ด ๋ณด์•˜๋Š”๋ฐ..

์Œ.. ์ข€ ๊ฐˆ์•„์—Ž์—ˆ๋‹ค ํฐ ํ‹€์€ ๋น„์Šทํ•˜์ง€๋งŒ ๋‚ด๊ฐ€ ๊ณ ์น  ์ˆ˜ ์žˆ๋Š” ๋ถ€๋ถ„ ๊ณ ์น˜๊ณ  ์ „๋ฐ˜์ ์œผ๋กœ ๋‹ค์‹œ ์†๋ดค๋˜ ๊ฑฐ ๊ฐ™๋‹ค.๐Ÿ˜ƒ๐Ÿ˜ƒ

 

๋งˆ์ง€๋ง‰ ์ž‘์—…์€ UI๋ฅผ ๊ตฌ์„ฑํ•˜๊ณ  ๋‚ ์”จ API์ธ Weather API๋ฅผ ์ž‘์—… ์ค‘์ด์—ˆ๋Š”๋ฐ ์ฝ”๋“œ ํŒŒ์ผ์„ ๋ณด๋‹ˆ ์ค‘๊ฐ„์— ๋ทฐ์— ๋ฟŒ๋ ค์ง€๊ธฐ ์ „์— ์ž ์‹œ ๋ฉˆ์ท„๋˜ ๊ฑฐ ๊ฐ™๋‹ค. ์ด์ œ๋Š” ๋‚ด๊ฐ€ ์• ํ”Œ ๊ฐœ๋ฐœ์ž ๊ณ„์ •์ด ์ƒ๊ฒจ ์ƒ๊ฐํ•ด ๋ณด๋‹ˆ ์• ํ”Œ์ด ์ œ๊ณตํ•˜๋Š” WeatherKit์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด?!

 

 

WeatherKit ์‹œ์ž‘ํ•˜๊ธฐ - Apple Developer

์š”๊ตฌ ์‚ฌํ•ญ, ์‹œ์ž‘ํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ๋„๊ตฌ ๋ฐ Dark Sky ๋‚ ์”จ ์„œ๋น„์Šค์—์„œ ์ „ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์‹ญ์‹œ์˜ค.

developer.apple.com

 

์• ํ”Œ์ด ์ œ๊ณตํ•˜๋Š” Kit ํ•œ๋ฒˆ ์จ๋ณด์ž ๋งˆ์Œ์„ ๋จน์—ˆ๋‹ค. WeatherKit ๊ด€๋ จ๋œ WWDC๋ฅผ ๋ณด๋ฉด์„œ ๋Œ€๋žต ์–ด๋–ค ๊ธฐ๋Šฅ์ธ์ง€ ํ™•์ธํ•˜์˜€๊ณ  ๊ธฐ๋ณธ์ ์œผ๋กœ ์˜ˆ์ œ๋กœ ์ œ๊ณตํ•ด ์ฃผ๋Š” ์ฝ”๋“œ๋ฅผ ๋ณด๋‹ˆ ์˜ค! ์ด๊ฑฐ ๊ฟ€์ด๋‹ค. ์ด์šฉํ•˜๊ธฐ ๋„ˆ๋ฌด ๊ฐ„๋‹จํ•˜๋‹ค๊ณ  ๋Š๊ผˆ๋‹ค. 

 

 

 

Meet WeatherKit - WWDC22 - Videos - Apple Developer

WeatherKit offers valuable weather data for your apps and services to help people stay up to date on the latest conditions. Learn how to...

developer.apple.com

 

๊ธฐ๋ณธ ์ฝ”๋“œ๋กœ ์ œ๊ณตํ•ด ์ฃผ๋Š” ๋‘ ์ฝ”๋“œ๋Š” ๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ์—ˆ๋‹ค.

์ฒซ ๋ฒˆ์งธ๋Š” import WeatherKit๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ด์šฉํ•ด ๋ณด๋Š” ์ฝ”๋“œ

๋”๋ณด๊ธฐ
import WeatherKit
import CoreLocation


let weatherService = WeatherService()

let syracuse = CLLocation(latitude: 43, longitude: -76)

let weather = try! await weatherService.weather(for: syracuse)

let temperature = weather.currentWeather.temperature

let uvIndex = weather.currentWeather.uvIndex

๋‘ ๋ฒˆ์งธ๋Š” REST API๋ฅผ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์ด์—ˆ๋‹ค

๋”๋ณด๊ธฐ
/* Request a token */
const tokenResponse = await fetch('https://example.com/token');
const token = await tokenResponse.text();

/* Get my weather object */
const url = "https://weatherkit.apple.com/1/weather/en-US/41.029/-74.642?dataSets=weatherAlerts&country=US"

const weatherResponse = await fetch(url, {
headers: {
"Authorization": token
}
});
const weather = await weatherResponse.json();

/* Check for active weather alerts */
const alerts = weather.weatherAlerts;
const detailsUrl = weather.weatherAlerts.detailsUrl;

๋‚˜๋Š” ์ฒซ ๋ฒˆ์งธ ๋ฐฉ๋ฒ•์„ ํ•˜๊ธฐ ์œ„ํ•ด ๊ตฌํ˜„ ๊ฐ€๋Šฅ์„ฑ์ด ๋˜๋Š”์ง€ ํ”Œ๋ ˆ์ด๊ทธ๋ผ์šด๋“œ์—์„œ ์‹คํ—˜ํ•ด ๋ณด์•˜๊ณ  ์‹ค์ œ๋กœ ๊ธˆ๋ฐฉ ๊ฐ’์ด ๋‚˜์˜ค๊ณ  ์ข€ ๋” ์ฝ”๋“œ๋ฅผ ๊ตฌํ˜„ ์•ˆ ํ•ด๋„ ์‰ฝ๊ฒŒ ๊ฐ’์ด ๋‚˜์™€ ์ด๊ฑธ ์•ˆ ์จ?? ๋ฌด์กฐ๊ฑด ์ด๊ฑฐ ์จ์•ผ์ง€ ๋งˆ์Œ์„ ๋จน์—ˆ๋‹ค. ๊ทธ๋ž˜์„œ ์ข€ ๋” ์ •๋ณด๋ฅผ ์ฐพ๊ธฐ ์œ„ํ•ด ๊ฒ€์ƒ‰ํ•œ ๊ฒฐ๊ณผ ์ด์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•๊ณผ ํฌ๋Ÿผ์„ ์ฐพ์•˜๋‹ค.

 

WeatherKit ํฌ๋Ÿผ

 

 

WeatherKit | Apple Developer Forums

Post not yet marked as solved I’m using WeatherKit REST API since September and all worked well until now. Sometimes the currentWeather key doesn’t exist when I’m parsing JSON. Does anybody here has the same problem? Posted by Nikita129873. Last upda

developer.apple.com

 

WeatherKit ํ”„๋ ˆ์ž„์›Œํฌ ๋ฌธ์„œ

 

WeatherKit | Apple Developer Documentation

Deliver weather conditions and alerts to your users.

developer.apple.com

 

 

์ ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ฐพ์œผ๋ฉด์„œ ๊ธฐ๋ณธ์— ๋งŒ๋“  ํ”„๋กœ์ ํŠธ์— ์ ์šฉํ•˜๋ ค๊ณ  ํ–ˆ๋‹ค. ์—ฌ๊ธฐ์—์„œ ํ—ˆํŠผ์ง“์„ ๋งŽ์ด ํ–ˆ๋‹คใ… ใ… 

๋ถ„๋ช… ๋ฐฉ๋ฒ•๋Œ€๋กœ ํ–ˆ๋Š”๋ฐ ํ”„๋กœ์ ํŠธ App Capabilities์— WeatherKit์ด ๋œจ์งˆ ์•Š์•„… ๋‹นํ™ฉ์„ ํ•˜์˜€๊ณ  ์ด๊ฒƒ์ €๊ฒƒ ์ฐพ์•„๋ณด๋ฉด์„œ ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋‚ด๋ ค๊ณ  ํ•ด ๋ณด๋ ค๊ณ  ํ–ˆ๋‹ค. ํฌ๋Ÿผ์—๋„ ๋‚˜์™€ ๊ฐ™์€ ํ˜„์ƒ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฐœ๋ฐœ์ž๊ฐ€ ์žˆ๋Š”์ง€ ์ฐพ์•„๋ณด๊ธฐ๋„ ํ–ˆ๋‹ค. ์ƒ๋‹นํžˆ ๋งŽ์€ ์‹œ๊ฐ„์„ ์จ์„œ ์–ด์ฉ” ์ˆ˜ ์—†์ด ๊ทธ๋Ÿผ ๋‘ ๋ฒˆ์งธ ๋ฐฉ๋ฒ•์œผ๋กœ ํƒํ•ด์•ผ ํ–ˆ๋‹ค. ๋ธ”๋กœ๊ทธ ๋‚ด์šฉ์„ ๋ณด๋ฉด์„œ ํ† ํฐ ์ด์•ผ๊ธฐ.. node?? ์ด์•ผ๊ธฐ๊ฐ€ ๋‚˜์˜จ ๊ฒƒ์„ ๋ณด๊ณ  ์Œ….. ๋„๋ง๊ฐˆ๊นŒ?ใ…‹ใ…‹ใ…‹ ์ƒ๊ฐ์„ ํ–ˆ์—ˆ๋‹ค. ๊ทธ๋ž˜์„œ ๋ฌด์กฐ๊ฑด ์ฒซ ๋ฒˆ์งธ ๋ฐฉ๋ฒ•์„ ์„ฑ๊ณต์‹œํ‚ค๊ธฐ ์œ„ํ•ด ๋” ์ฐพ์•„ ํ—ค๋งธ๋‹ค.

iOS ์•ฑ ํ”„๋กœ์ ํŠธ๋กœ ๋งŒ๋“ค๋ฉด App Capabilities์— WeatherKit์ด ๋‚˜์˜ค๊ณ  WatchOS๋กœ ํ”„๋กœ์ ํŠธ ๋งŒ๋“ค์–ด์„œ App Capabilities๋ฅผ ํ™•์ธํ•˜๋ฉด ์•ˆ ๋œจ๋Š” ๊ฒŒ ์˜๋ฌธ์ด์—ˆ๋‹ค. ์ˆœ๊ฐ„ ๋“  ์ƒ๊ฐ์ด ์•„์ดํฐ๊ณผ ๋‹ค๋ฅด๊ฒŒ ์• ํ”Œ์›Œ์น˜์—ฌ์„œ ์ด๋Ÿฐ ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ๋‚ด์žฅ ์•ˆ ์‹œํ‚ค๋Š” ๊ฑด๊ฐ€? ์˜๋ฌธ๋„ ๋“ค๊ณ  ๊ทธ๋Ÿผ ์• ํ”Œ์›Œ์น˜์— ์žˆ๋Š” ๋‚ ์”จ ์ •๋ณด๋“ค์€ ๋‚ด ํœด๋Œ€ํฐ์—์„œ ๋„˜๊ฒจ์ฃผ๋Š” ๊ฑด๊ฐ€? ์ƒ๊ฐ๋„ ๋“ค์—ˆ๋˜ ์ ์ด ์žˆ๋‹ค. ์ง„์งœ ์„ค๋งˆ ๊ทธ๋Ÿฌ๊ฒ ์–ด๋ผ๋Š” ์ƒ๊ฐ์œผ๋กœ ์ถ”๊ฐ€ํ•˜๋Š” ํ™”๋ฉด์œผ๋กœ ๋„˜์–ด๊ฐ€์„œ ์ž์„ธํžˆ ์‚ดํŽด๋ดค๋‹ค.

 

 

๊ทธ๋ž˜ ์ด๊ฑฐ์ง€ ์ œ๊ณต์„ ์•ˆ ํ•  ๋ฆฌ๊ฐ€ ์—†์ง€!

์ด๊ฒƒ์„ ๋‹น๊ทผ ์‚ผ์•„ ๊ฐ€๋Šฅ์„ฑ ์žˆ๋‹ค! ๋‚ด๊ฐ€ ํ•ด๋‹ต์„ ๋ชป ์ฐพ์€ ๊ฑฐ๋ผ๋Š” ์ƒ๊ฐ์œผ๋กœ ํ•˜๋‚˜์”ฉ ์‚ดํŽด๋ณด๊ธฐ ์‹œ์ž‘ํ–ˆ๊ณ  ๊ด€๋ จ๋œ ๊ฒƒ์„ ๋ชจ๋‘ ์ฒดํฌํ•˜๊ณ  ๋„˜์–ด๊ฐ€๊ณ  ์ด ์‚ฌ์ดํŠธ์—์„œ ๋งŒ๋“ค์–ด์•ผ ํ•˜๋Š” ๊ฒƒ๋“ค์„ ์ „๋ถ€ ๋งŒ๋“ค๊ณ  ๊ธฐ๋ณธ ๊ณ„์ • ์„ธํŒ… ๊ฐ™์€ ๊ฒƒ์„ ํ–ˆ๋˜ ๊ฑฐ ๊ฐ™๋‹ค?!

๊ฐ‘์ž๊ธฐ ๋จธ๋ฆฟ์†์— ๋– ์˜ค๋Š” ๊ฒƒ์€ ์ด๋ ‡๊ฒŒ ๊ตฌ์„ฑํ•˜๊ณ  ๋ฐ”๋กœ ์ ์šฉ๋˜๋Š” ๊ฒƒ์ด ์•„๋‹Œ ์–ด๋Š ์ •๋„ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฐ๋‹ค๋Š” ๋ฌธ๊ตฌ๊ฐ€ ์ƒ๊ฐ์ด ๋‚˜ ์ œ๋ฐœ ๋ผ๋ผ ๊ธฐ๋„ํ•˜๋ฉด์„œ ๊ธฐ๋‹ค๋ ธ๋‹คใ…‹ใ…‹ ์–ด๋Š ์ˆœ๊ฐ„ App Capabilities์— WeatherKit์ด ๋œจ๋ฉด์„œ ๋“œ๋””์–ด ์ž‘์—…์„ ํ•  ์ˆ˜ ์žˆ๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ๋‹ค!!

 

์—ด์‹ฌํžˆ WeatherKit ํ”„๋ ˆ์ž„์›Œํฌ ๋ฌธ์„œ๋ฅผ ๋ณด๋ฉด์„œ ๋‚ด๊ฐ€ ํ•„์š”ํ•œ ๊ธฐ๋Šฅ๋“ค์„ ๋ฝ‘์•„์„œ ์‚ฌ์šฉํ•˜์˜€๋‹ค.

์ž‘์—…ํ•˜๋ฉด์„œ ๋Š๋‚€ ์ ์€ ์•„๋ฌด๋ž˜๋„ ์• ํ”Œ์ด ์ œ๊ณตํ•˜๋Š” ํ”„๋ ˆ์ž„์›Œํฌ๋‹ค ๋ณด๋‹ˆ ๊ผผ๊ผผํ•˜๊ฒŒ ํƒ€์ž… ์œ ํ˜•์ด ์„ ์–ธ๋˜์–ด ์žˆ์—ˆ๊ณ  ๋‚˜๋Š” ๊ทธ๊ฒƒ์„ ์ ์ ˆํžˆ ๋ทฐ์—์„œ ๋ณด์ผ ์ˆ˜ ์žˆ๋„๋ก ๊ฐ’์„ ๋ฝ‘์•„๋‚ด๊ณ  ์˜์–ด๋กœ ์„ ์–ธ๋˜์–ด ์žˆ๋Š” ๊ฒƒ๋“ค์„ switch ๋ฌธ๋“ค ํ†ตํ•ด ํ•œ๊ธ€๋กœ ๋ฐ”๊พธ๋Š” ์ž‘์—…์„ ํ•ด๋ณผ ์ˆ˜ ์žˆ์—ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋‚ ์”จ ๋ฐ์ดํ„ฐ๋‹ค ๋ณด๋‹ˆ ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ๊ฒฝ์šฐ๋ฅผ ๊ณ ๋ คํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋“ค์„ ๋งŒ๋“ค์–ด ๋‘” ๊ฒƒ ๊ฐ™๋‹ค.

 


๋‚ ์”จ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ์ž‘์—…์€ ๋๋‚ฌ์ง€๋งŒ ์ด ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์ถœ์‹œ๋ฅผ ํ•˜๋ ค๋ฉด ์ถ”๊ฐ€์ ์œผ๋กœ ๋ช…์‹œํ•ด์•ผ ํ•  ๋ฐ์ดํ„ฐ๋“ค์ด ์žˆ์–ด ๊ทธ ๋ถ€๋ถ„์„ ์ถ”๊ฐ€์ ์œผ๋กœ ์ž‘์—…ํ•˜๊ณ  ๋˜ ๋‹ค๋ฅธ ๊ธฐ๋Šฅ์„ ๊ฐœ๋ฐœํ•ด ๋ณผ ์ƒ๊ฐ์ด๋‹ค.

์˜ค๋žœ๋งŒ์— ํ”„๋กœ์ ํŠธ๋ฅผ ์—ด์–ด๋ณด๊ณ  ์ฝ”๋“œ๋ฅผ ๋ณด๋‹ˆ ์‚ด์ง ์–ด์ƒ‰ํ•œ ๊ฐ์ด ์žˆ์—ˆ์ง€๋งŒ ์ด์ œ๋Š” ์‹œ๊ฐ„์ด ์—ฌ์œ ๊ฐ€ ์žˆ์„ ๋•Œ ์กฐ๊ธˆ์”ฉ ํ•ด๋ด์•ผ๊ฒ ๋‹ค. ๊ทธ๋ž˜์•ผ SwiftUI ๊ฐ์„ ์žƒ์ง€ ์•Š์„ ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•œ๋‹คใ…Žใ…Ž!!

 

์ฐธ๊ณ ํ•œ ๋ธ”๋กœ๊ทธ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค!!

https://ios-daniel-yang.tistory.com/20

https://sujinnaljin.medium.com/ios-weatherkit-rest-api-%EC%9D%B8%EC%A6%9D-%EC%9A%94%EC%B2%AD-b3fad82d1c71

https://blog.makwanbk.com/weatherkit-build-a-simple-ios-weather-app