搜索

PythonReactSEOPDF
GitHub Skill

notification-expert

Push notification and UNUserNotificationCenter expert. Use when working with APNs, actionable notifications, notification categories, or local notifications on watchOS/iOS.

fotescodev☆ 0 仓库 Stars0 仓库 Forks

安装与使用

请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。

查看来源 ↗使用指南

技能说明

Push Notification Expert

Instructions

When working with notifications:

  1. Understand the notification flow (APNs -> App -> User)
  2. Properly configure notification categories and actions
  3. Handle both foreground and background delivery
  4. Test notification handling thoroughly

watchOS Notification Patterns

Permission Request
UNUserNotificationCenter.current().requestAuthorization(
    options: [.alert, .sound, .badge]
) { granted, error in
    if granted {
        // Register for remote notifications
        WKExtension.shared().registerForRemoteNotifications()
    }
}
Notification Categories
// Define actions
let approveAction = UNNotificationAction(
    identifier: "APPROVE",
    title: "Approve",
    options: [.foreground]
)

let rejectAction = UNNotificationAction(
    identifier: "REJECT",
    title: "Reject",
    options: [.destructive]
)

// Create category
let category = UNNotificationCategory(
    identifier: "ACTION_CATEGORY",
    actions: [approveAction, rejectAction],
    intentIdentifiers: [],
    options: [.customDismissAction]
)

// Register
UNUserNotificationCenter.current().setNotificationCategories([category])
Handling Responses
extension AppDelegate: UNUserNotificationCenterDelegate {
    func userNotificationCenter(
        _ center: UNUserNotificationCenter,
        didReceive response: UNNotificationResponse,
        withCompletionHandler completionHandler: @escaping () -> Void
    ) {
        switch response.actionIdentifier {
        case "APPROVE":
            // Handle approval
        case "REJECT":
            // Handle rejection
        case UNNotificationDefaultActionIdentifier:
            // User tapped notification body
        case UNNotificationDismissActionIdentifier:
            // User dismissed notification
        default:
            break
        }
        completionHandler()
    }
}
Local Notifications
let content = UNMutableNotificationContent()
content.title = "Action Required"
content.body = "Claude needs your approval"
content.categoryIdentifier = "ACTION_CATEGORY"
content.userInfo = ["action_id": "abc123"]

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)

UNUserNotificationCenter.current().add(request)

Best Practices

  • Always handle notification permissions gracefully
  • Use actionable notifications for quick responses
  • Include relevant data in userInfo dictionary
  • Test with both app foreground and background
  • Handle notification dismissal appropriately

使用示例

查看来源仓库中的使用示例与配置说明。

查看来源 ↗

来源历史

收录时间
2026-01-20
索引更新时间
2026-01-26
Branch
main

收录与同步日期属于本站记录。源码修改历史请查看来源仓库。

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!