Created: - docs/examples/QUICK_START.md: Minimal working example with platform setup - docs/examples/COMMON_PATTERNS.md: Common patterns (error handling, scheduling, recovery) Updated docs/00-INDEX.md to link examples section. Verification: - Documentation created and linked ✅ - Examples follow best practices ✅
84 lines
1.9 KiB
Markdown
84 lines
1.9 KiB
Markdown
# Common Integration Patterns
|
|
|
|
**Purpose:** Common patterns and best practices for Daily Notification Plugin integration.
|
|
**Owner:** Development Team
|
|
**Last Updated:** 2025-12-22
|
|
**Status:** active
|
|
|
|
---
|
|
|
|
## Error Handling
|
|
|
|
```typescript
|
|
import { DailyNotification, DailyNotificationError, ErrorCode } from '@timesafari/daily-notification-plugin';
|
|
|
|
try {
|
|
await DailyNotification.createSchedule({
|
|
id: 'daily-morning',
|
|
kind: 'notify',
|
|
clockTime: '09:00',
|
|
enabled: true
|
|
});
|
|
} catch (error) {
|
|
if (error instanceof DailyNotificationError) {
|
|
switch (error.code) {
|
|
case ErrorCode.PERMISSION_DENIED:
|
|
// Request permission first
|
|
await DailyNotification.requestPermission();
|
|
break;
|
|
case ErrorCode.INVALID_TIME_FORMAT:
|
|
// Fix time format (use HH:mm)
|
|
console.error('Invalid time format');
|
|
break;
|
|
default:
|
|
console.error('Error:', error.message);
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
## Scheduling Multiple Notifications
|
|
|
|
```typescript
|
|
const times = ['09:00', '12:00', '18:00'];
|
|
|
|
for (const time of times) {
|
|
await DailyNotification.createSchedule({
|
|
id: `daily-${time.replace(':', '')}`,
|
|
kind: 'notify',
|
|
clockTime: time,
|
|
enabled: true
|
|
});
|
|
}
|
|
```
|
|
|
|
## Checking Schedule Status
|
|
|
|
```typescript
|
|
const { schedules } = await DailyNotification.getSchedulesWithStatus();
|
|
|
|
schedules.forEach(schedule => {
|
|
console.log(`${schedule.id}: ${schedule.status} (scheduled: ${schedule.isActuallyScheduled})`);
|
|
});
|
|
```
|
|
|
|
## Recovery After App Restart
|
|
|
|
The plugin automatically recovers missed notifications on app launch. To check recovery status:
|
|
|
|
```typescript
|
|
// Recovery happens automatically on app launch
|
|
// Check history for recovery events
|
|
const { history } = await DailyNotification.getHistory({
|
|
kind: 'recovery',
|
|
limit: 10
|
|
});
|
|
```
|
|
|
|
---
|
|
|
|
**See also:**
|
|
- [Quick Start](./QUICK_START.md) — Minimal working example
|
|
- [Integration Guide](../integration/INTEGRATION_GUIDE.md) — Full integration guide
|
|
|