diff --git a/docs/00-INDEX.md b/docs/00-INDEX.md index 74ecab9..8c5e105 100644 --- a/docs/00-INDEX.md +++ b/docs/00-INDEX.md @@ -36,6 +36,13 @@ These files define the current truth about project state, decisions, and verific --- +## Examples + +- **[Quick Start](./examples/QUICK_START.md)** — Minimal working example +- **[Common Patterns](./examples/COMMON_PATTERNS.md)** — Common integration patterns and best practices + +--- + ## Archive & Reference-only - **`docs/_archive/`** — Historical artifacts, preserved for audit trail (not part of active doc surface) diff --git a/docs/examples/COMMON_PATTERNS.md b/docs/examples/COMMON_PATTERNS.md new file mode 100644 index 0000000..3489d97 --- /dev/null +++ b/docs/examples/COMMON_PATTERNS.md @@ -0,0 +1,83 @@ +# 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 + diff --git a/docs/examples/QUICK_START.md b/docs/examples/QUICK_START.md new file mode 100644 index 0000000..cc8c0de --- /dev/null +++ b/docs/examples/QUICK_START.md @@ -0,0 +1,58 @@ +# Quick Start Guide + +**Purpose:** Minimal working example for Daily Notification Plugin. +**Owner:** Development Team +**Last Updated:** 2025-12-22 +**Status:** active + +--- + +## Minimal Working Example + +```typescript +import { DailyNotification } from '@timesafari/daily-notification-plugin'; + +// 1. Request permission +const { state } = await DailyNotification.requestPermission(); +if (state !== 'granted') { + console.error('Permission denied'); + return; +} + +// 2. Create schedule +const { schedule } = await DailyNotification.createSchedule({ + id: 'daily-morning', + kind: 'notify', + clockTime: '09:00', + enabled: true +}); + +// 3. Verify schedule +const { schedules } = await DailyNotification.getSchedules(); +console.log('Active schedules:', schedules); +``` + +## Platform Setup + +### iOS +Add to `Info.plist`: +```xml +BGTaskSchedulerPermittedIdentifiers + + com.timesafari.dailynotification.fetch + +``` + +### Android +Add to `AndroidManifest.xml`: +```xml + + +``` + +--- + +**See also:** +- [Common Patterns](./COMMON_PATTERNS.md) — Common integration patterns +- [Integration Guide](../integration/INTEGRATION_GUIDE.md) — Full integration guide +