すべてのオープンソースパッケージ
プラットフォームSwift

iOS-Notification-Framework

iOS の64件制限を超えてローカル通知をスケジュールし、タップをルーティングし、APNs 経由でプッシュを送信します。

3スター数最新リリース: v2.0.0 · 更新日: 2026年10月15日
対応プラットフォーム:iOS 17macOS 14watchOS 10visionOS 1

ライセンス: MIT

NotificationKit は、デバイス上で通知をスケジュールするアプリと、それらにプッシュを送るサーバーのための Swift パッケージです。UserNotifications を値型でラップし、サイレントに失敗する部分を修正します: iOS はアプリの保留中の通知のうち直近の64件だけを保持し、残りはエラーなしに破棄されます。一部の無効な値は throw ではなくアプリをクラッシュさせ、delegate のコールバックは Swift の concurrency から使いづらいものでした。もう一つのライブラリ NotificationKitAPNs は、アプリが読み取るのと同じ payload 型で APNs 経由のプッシュを送信します。どちらのライブラリも Apple の SDK 以外に依存関係はありません。

機能

  • 64件を超えても通知は失われません: NotificationScheduler は直近の64件を iOS に渡し、残りは保存済みの queue に保持し、空きができると順に繰り上げます
  • quiet hours と頻度の上限は、通知が発火する時刻に対してチェックされるため、21:00に設定された23:00向けのリマインダーは朝まで待機します
  • クラッシュではなくエラーに: 60秒未満の repeating interval、NaN の relevance score、25時といった値は、UNUserNotificationCenter に渡る前に NotificationValidationError を throw します
  • タップ、action、deep link を値として扱います: NotificationEventHandler は delegate のコールバックを AsyncStream に変換し、DeepLinkRouter は許可された scheme と host からのみ画面を開きます
  • 両側に対応するプッシュ: APNs のサイズ制限を反映した型付きの PushPayload、全体が出力されることのない DeviceToken、メディアをダウンロードする Notification Service Extension、token 認証に対応した APNs クライアント
  • InMemoryNotificationCenter はシステムの64件制限を維持するため、スケジューリングのロジックを普通のユニットテストで実行できます

クイックスタート

swift
1import NotificationKit
2import SwiftUI
3 
4let scheduler = NotificationScheduler() // one for the whole app
5 
6struct ContentView: View {
7 var body: some View {
8 Button("Remind me in 10 seconds") {
9 Task {
10 do {
11 try await scheduler.requestAuthorization()
12 try await scheduler.schedule(LocalNotification(
13 id: "water",
14 title: "Time for a glass of water",
15 body: "You asked for this reminder 10 seconds ago.",
16 trigger: .after(seconds: 10)
17 ))
18 } catch {
19 print("Could not schedule the reminder:", error)
20 }
21 }
22 }
23 }
24}

インストール

Swift Package Manager

swift
1dependencies: [
2 .package(url: "https://github.com/muhittincamdali/iOS-Notification-Framework.git", from: "2.0.0")
3],
4targets: [
5 .target(name: "YourApp", dependencies: [
6 .product(name: "NotificationKit", package: "iOS-Notification-Framework")
7 ]),
8 // A server or command-line tool that sends pushes:
9 .executableTarget(name: "PushServer", dependencies: [
10 .product(name: "NotificationKitAPNs", package: "iOS-Notification-Framework")
11 ])
12]

Xcode

text
1https://github.com/muhittincamdali/iOS-Notification-Framework.git

スクリーンショット

iPhone シミュレータ上のサンプルアプリ NotificationLab のリマインダーバナー、ライトモード
iPhone シミュレータ上のサンプルアプリ NotificationLab のリマインダーバナー、ダークモード
システムに64件、残りが queue にあるスケジュール済みリスト、ライトモード
システムに64件、残りが queue にあるスケジュール済みリスト、ダークモード
シミュレータのプッシュから開かれた注文画面、ライトモード
シミュレータのプッシュから開かれた注文画面、ダークモード

タイムライン

  1. 通知フレームワークのプロトタイプとしてリポジトリが公開されました。初期のコミットの大半はドキュメント、サンプル、CI でした

  2. v1.0.0 がリリースされました。main は builder ベースの API を伴う単一のコミットから再開されました

  3. 小さなプロトタイプの追加: SwiftUI のプレビュー、Live Activity manager、predictive push の型

  4. テスト可能な notification center を中心に 2.0.0 として作り直されました。プロトタイプのソースは削除され、1.x の API は維持されていません

リンク

関連記事

記事を読む (English)