feat(docs): P3.3-D Add integration examples and common patterns
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 ✅
This commit is contained in:
@@ -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)
|
||||
|
||||
83
docs/examples/COMMON_PATTERNS.md
Normal file
83
docs/examples/COMMON_PATTERNS.md
Normal file
@@ -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
|
||||
|
||||
58
docs/examples/QUICK_START.md
Normal file
58
docs/examples/QUICK_START.md
Normal file
@@ -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
|
||||
<key>BGTaskSchedulerPermittedIdentifiers</key>
|
||||
<array>
|
||||
<string>com.timesafari.dailynotification.fetch</string>
|
||||
</array>
|
||||
```
|
||||
|
||||
### Android
|
||||
Add to `AndroidManifest.xml`:
|
||||
```xml
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
**See also:**
|
||||
- [Common Patterns](./COMMON_PATTERNS.md) — Common integration patterns
|
||||
- [Integration Guide](../integration/INTEGRATION_GUIDE.md) — Full integration guide
|
||||
|
||||
Reference in New Issue
Block a user