概要
StoreKit 2 を使用した自動更新サブスクリプション。月額と年額の2プランを提供。
購入状態は StoreKitService がシングルトンで管理し、Transaction.updates を監視して即時反映。
関連画面
処理フロー(購入)
sequenceDiagram
participant U as User
participant PV as PaywallView
participant SK as StoreKitService
participant AS as App Store
participant TX as Transaction.updates
U->>PV: プラン選択 + 購入
PV->>SK: purchase(product)
SK->>AS: Product.purchase()
AS->>U: Apple ID認証
U-->>AS: 承認
AS-->>SK: 結果(success/userCancelled/pending)
alt success
SK->>SK: verification チェック
SK->>SK: transaction.finish()
SK->>SK: isPremium = true
SK->>PV: 完了通知
else userCancelled
SK-->>PV: キャンセル
else pending
SK-->>PV: 「処理中」
end
TX-->>SK: バックグラウンド更新通知(自動更新等)
SK->>SK: refreshPremiumStatus()
商品定義
| プラン | Product ID | 更新 |
| 月額 | com.happyboy1002.RankingStadium.premium.monthly | 毎月自動更新 |
| 年額 | com.happyboy1002.RankingStadium.premium.yearly | 毎年自動更新 |
プレミアム特典
- 広告非表示(実装予定)
- 無料作成枠の拡大
- 月次ポイントボーナス(実装予定)
- 限定機能(v1.1以降)
ビジネスルール
- 購入は Apple ID(Family Sharing対応)
- 復元は
restorePurchases() でいつでも可
- 本番判定は
isAppStoreRelease(DEBUG/TestFlightで偽)
- 起動時に
checkCurrentEntitlements() で購買状態確認
- テスト時は
debugOverridePremium フラグで強制プレミアム化
外部連携
| 連携先 | 用途 |
| StoreKit 2 | Product 取得・purchase / restore / Transaction.updates |
| App Store Connect | 商品設定・価格・サブスク期間 |
| users.isPremium | サブスク状態のキャッシュ(Supabase) |
エラー処理
| 発生条件 | 対応 |
| 商品未取得 | ProgressViewで再試行 |
| verification失敗 | 「決済の検証に失敗しました」 + サポート誘導 |
| userCancelled | サイレント |
| pending(保護者承認待ち) | 「処理中です」表示、Transaction.updates で後続処理 |
| 復元時に該当商品なし | 「復元できる商品がありません」 |
実装メモ
- StoreKitService は
@Observable @MainActor シングルトン
- listenForTransactions() で Transaction.updates 監視(無限Task)
- products は loadProducts() で月額→年額の順にソート
- Logger.StoreKit カテゴリ
- StoreKit Configuration ファイルでローカルテスト
変更履歴
| バージョン | 日付 | 変更内容 |
| 1.0 | 2026-05-09 | 初版作成 |