概要
StoreKit 2 を使用したサブスクリプション課金。月額・年額の2プラン。Trial(無料試用)対応、Transaction.updates でリアルタイム反映。
関連画面
提供商品
| プラン | Product ID |
| 月額 | com.happyboy1002.WorkoutDiary.premium.monthly.v2 |
| 年額 | com.happyboy1002.WorkoutDiary.premium.yearly |
StoreManager API
@Observable @MainActor
final class StoreManager {
var products: [Product]
var purchasedProductIDs: Set<String>
var isPremium: Bool
var trialRemainingDays: Int?
func loadProducts() async
func purchase(_ product: Product) async throws
func restorePurchases() async throws
func startTransactionListener()
func checkVerified<T>(_ result: VerificationResult<T>) throws -> T
}
Trial(無料試用)
- App Store Connect でプロモーションオファーとして設定
- Transaction listener で expirationDate を監視
trialRemainingDays 計算 → ContentView バナーで残日数表示
- v1.0.5 で Trial 終了通知追加検討
ビジネスルール
- 購入は Apple ID(Family Sharing 対応)
- 復元は
AppStore.sync() でいつでも可
- 未認証Transactionは finish() しない(再検証可能)
- Family Sharing 購入の判定は
transaction.ownershipType
外部連携
| 連携先 | 用途 |
| StoreKit 2 | Product 取得・purchase / Transaction.updates |
| App Store Connect | 商品設定・価格 |
エラー処理
| 発生条件 | 対応 |
| verification失敗 | 「決済の検証に失敗しました」 |
| userCancelled | サイレント |
| pending | 「処理中です」+ Transaction.updates 待機 |
変更履歴
| バージョン | 日付 | 変更内容 |
|---|
| 1.0 | 2026-05-09 | 初版作成 |