가이드
__CAPGO_KEEP_0__ 실시간 활동 튜토리얼
Using @capgo/capacitor-live-activities
Capacitor Live Activities 플러그인 인터페이스
설치
bun add @capgo/capacitor-live-activities
bunx cap sync
이 플러그인이 제공하는 것
areActivitiesSupported- 이 장치에서 라이브 액티비티가 지원되는지 확인합니다. iOS 16.1 이상과 장치 지원이 필요합니다.startActivity- 특정 레이아웃과 데이터와 함께 새로운 라이브 액티비티를 시작합니다.updateActivity- 기존 라이브 액티비티를 새로운 데이터로 업데이트합니다.endActivity- 라이브 액티비티를 종료합니다.
사용 예
areActivitiesSupported
이 장치에서 라이브 액티비티가 지원되는지 확인합니다. iOS 16.1 이상과 장치 지원이 필요합니다.
import { CapgoLiveActivities } from '@capgo/capacitor-live-activities';
const { supported, reason } = await CapgoLiveActivities.areActivitiesSupported();
if (supported) {
console.log('Live Activities are supported!');
} else {
console.log('Not supported:', reason);
}
startActivity
특정 레이아웃과 데이터와 함께 새로운 라이브 액티비티를 시작합니다.
import { CapgoLiveActivities } from '@capgo/capacitor-live-activities';
const { activityId } = await CapgoLiveActivities.startActivity({
layout: {
type: 'container',
direction: 'horizontal',
children: [
{ type: 'text', content: 'Order #{{orderNumber}}', fontSize: 16, fontWeight: 'bold' },
{ type: 'text', content: '{{status}}', fontSize: 14, color: '#666666' }
]
},
dynamicIslandLayout: {
expanded: {
leading: { type: 'image', source: 'sfSymbol', value: 'box.truck' },
trailing: { type: 'text', content: '{{eta}}' },
center: { type: 'text', content: '{{status}}' },
bottom: { type: 'progress', value: 'progress' }
},
compactLeading: { type: 'image', source: 'sfSymbol', value: 'box.truck' },
compactTrailing: { type: 'text', content: '{{eta}}' },
minimal: { type: 'image', source: 'sfSymbol', value: 'box.truck' }
},
data: {
orderNumber: '12345',
status: 'On the way',
eta: '10 min',
progress: 0.6
}
});
console.log('Started activity:', activityId);
updateActivity
기존 라이브 액티비티를 새로운 데이터로 업데이트합니다.
import { CapgoLiveActivities } from '@capgo/capacitor-live-activities';
await CapgoLiveActivities.updateActivity({
activityId: 'abc123',
data: {
status: 'Arrived!',
eta: 'Now',
progress: 1.0
},
alertConfiguration: {
title: 'Delivery Update',
body: 'Your order has arrived!'
}
});
endActivity
실시간 활동을 종료합니다.
import { CapgoLiveActivities } from '@capgo/capacitor-live-activities';
await CapgoLiveActivities.endActivity({
activityId: 'abc123',
data: { status: 'Delivered' },
dismissalPolicy: 'after',
dismissAfter: Date.now() + 3600000 // 1 hour from now
});
전체 참조
- GitHub https://github.com/Cap-go/capacitor-실시간-활동들/
- 문서: /docs/plugins/live-activities/