WeatherKit 및 CalendarKit 통합으로 더 스마트한 웨어러블 앱 만들기
Source: Dev.to
프로젝트 개요
- 현재 날씨(온도, 상태) 표시
- CalendarKit에서 오늘 일정 가져오기
- 상황에 맞는 팁 제공(예: “오전 10시 회의 전에 우산을 챙기세요”)
설정
module.json5에서 키트 활성화
{
"module": {
"requestPermissions": [
"ohos.permission.READ_CALENDAR",
"ohos.permission.INTERNET",
"ohos.permission.ACCESS_INTERNET"
],
"deviceType": ["wearable"],
"abilities": [
{
"name": "EntryAbility",
"srcEntry": "./ets/MainAbility/EntryAbility.ets"
}
]
},
"features": [
{ "name": "weather", "optional": false },
{ "name": "calendar", "optional": false }
]
}
.ets 파일에 필요한 키트 import
import weather from '@ohos.weather';
import calendar from '@ohos.calendar';
단계 1: WeatherKit으로 날씨 데이터 가져오기
재사용 가능한 WeatherService를 만들어 현재 위치를 기반으로 날씨 정보를 얻습니다(위치 권한이 부여되었다고 가정).
// WeatherService.ets
export class WeatherService {
async getCurrentWeather(): Promise {
const weatherInfo = await weather.getWeatherByLocation();
return {
temperature: weatherInfo.realtime?.temperature ?? '--',
condition: weatherInfo.realtime?.text ?? 'Unknown'
};
}
}
단계 2: CalendarKit으로 오늘 일정 가져오기
CalendarKit API를 사용해 오늘 일정을 가져옵니다.
// CalendarService.ets
export class CalendarService {
async getTodayEvents(): Promise {
const start = new Date();
start.setHours(0, 0, 0, 0);
const end = new Date();
end.setHours(23, 59, 59, 999);
const events = await calendar.queryEvents({
beginTime: start.getTime(),
endTime: end.getTime()
});
return events.map(event =>
`${new Date(event.beginTime).toLocaleTimeString()} - ${event.title}`
);
}
}
단계 3: 스마트 제안 생성
ContextEngine은 날씨 데이터와 캘린더 일정을 결합해 일일 조언을 제공합니다.
// ContextEngine.ets
import { WeatherService } from './WeatherService';
import { CalendarService } from './CalendarService';
export class ContextEngine {
private weatherService = new WeatherService();
private calendarService = new CalendarService();
async getDailySuggestion(): Promise {
const weather = await this.weatherService.getCurrentWeather();
const events = await this.calendarService.getTodayEvents();
if (weather.condition.includes('Rain') && events.length > 0) {
return `🌧️ Rain expected. Take an umbrella before your "${events[0]}"`;
} else if (parseInt(weather.temperature) > 30) {
return `🥵 It's hot today. Stay hydrated and wear light clothes.`;
} else {
return `✅ Weather looks good. You’re all set for your day!`;
}
}
}
단계 4: 스마트워치 UI에 모두 표시
간단한 ArkUI 페이지가 날씨 정보, 캘린더 일정, 스마트 제안을 보여줍니다.
// pages/PlannerPage.ets
import { ContextEngine } from '../services/ContextEngine';
@Entry
@Component
struct PlannerPage {
@State temperature: string = '--';
@State condition: string = 'Loading...';
@State events: string[] = [];
@State suggestion: string = 'Analyzing...';
private contextEngine = new ContextEngine();
async aboutToAppear() {
const weather = await this.contextEngine.weatherService.getCurrentWeather();
const events = await this.contextEngine.calendarService.getTodayEvents();
const smartSuggestion = await this.contextEngine.getDailySuggestion();
this.temperature = weather.temperature;
this.condition = weather.condition;
this.events = events;
this.suggestion = smartSuggestion;
}
build() {
Column({ space: 10 }) {
Text(`🌡️ ${this.temperature}° - ${this.condition}`)
.fontSize(20)
.fontWeight(FontWeight.Bold)
Text('📅 Today’s Events:')
.fontSize(18)
.fontWeight(FontWeight.Medium)
ForEach(this.events, (event: string) => {
Text(event).fontSize(14)
}, item => item)
Divider()
Text(`🧠 Suggestion:`).fontSize(18).fontWeight(FontWeight.Medium)
Text(this.suggestion).fontSize(16).fontColor(Color.Blue)
}
.padding(20)
}
}
출력 미리보기
시계 화면 예시:
🌡️ 22° — Light Rain
📅 Today’s Events:
09:00 AM - Team Stand‑up
14:30 PM - Project Review
🧠 Suggestion:
🌧️ Rain expected. Take an umbrella before your "09:00 AM - Team Stand‑up"
최종 생각
HarmonyOS 웨어러블은 피트니스 추적을 넘어 더 많은 일을 할 수 있습니다. WeatherKit과 CalendarKit을 결합하면 실시간으로 사용자에게 진정으로 도움이 되는 깊이 있는 개인화 경험을 제공할 수 있습니다.
더 나아가고 싶다면?
- LocationKit을 사용해 위치 정확도를 향상시킵니다.
- BackgroundTaskKit을 추가해 데이터를 주기적으로 새로 고칩니다.
- 며칠에 걸친 예보나 반복 일정으로 확장합니다.
결론
Smart Day Planner 앱은 개발자가 HarmonyOS 웨어러블에서 WeatherKit과 CalendarKit을 활용해 진정한 상황 인식 및 지능형 사용자 경험을 만들 수 있음을 보여줍니다. 동적으로 결합함으로써:
- 실시간 날씨 상황
- 오늘 일정
- 논리 기반 상황 제안
웨어러블은 수동적인 액세서리에서 능동적인 비서로 변모합니다. 이 통합은 다음에 적용될 수 있습니다:
- 건강 앱(날씨에 따라 수분 섭취 알림 조정)
- 피트니스 앱(폭풍이 오는 날 실내 운동 추천)
- 생산성 도구(옷차림이나 통근 팁 제안)
- 스마트 옷장 앱(캘린더와 예보를 기반으로 옷차림 제안)
이러한 핵심 키트를 기반으로 개발자는 다양한 상황에 로직을 확장해 깊이 있는 개인화 HarmonyOS 경험을 제공할 수 있습니다.
참고 자료
- OpenCms demo – Huawei Developer
- 추가 문서는 Huawei Developer 포털의 WeatherKit, CalendarKit, LocationKit 및 BackgroundTaskKit을 참고하세요.