型プロパティ


updates


システムがアプリ外部または他のデバイスで発生する取引を作成または更新するときに取引を発行する非同期シーケンス。


iOS 15.0+ iPadOS 15.0+ macOS 12.0+ tvOS 15.0+

VisionOS 1.0+ WatchOS 8.0+

var updates: Transaction.Transactions { get }




以下で言及


あなたのアプリで再獲得提供をサポート
(Supporting win-back offers in your app)


あなたのアプリでサブスクリプション提供コードをサポート
(Supporting subscription offer codes in your app)


サンドボックス環境での再獲得提供のテスト
(Testing win-back offers in the sandbox environment)


アプリ外での購入をテストする


あなたのアプリ内での売買による再獲得オファー
(Merchandising win-back offers in your app)


議論


アプリの実行中に新しいトランザクションを受信するには、updates を使用します。このシーケンスは、Ask to Buy の取引、サブスクリプションオファーコードの引き換え、顧客が App Store で行う購入など、アプリ外で発生する取引を受信します。また、顧客が別のデバイス上のあなたのアプリで完了した取引も発行します。


同じデバイスでアプリ内購入が成功すると、StoreKit は Product.PurchaseResult.success(_:) を通じて取引を返すことに注意してください。


重要

アプリの起動後すぐに視聴者からの取引を反復処理する Task を作成します。あなたのアプリに未完了の取引がある場合、updates 視聴者はアプリの起動直後にそれらを 1 回受信します。これらの取引を視聴する Task がないと、あなたのアプリはそれらを見逃す可能性があります。

以下の例は、初期化する時に Task を作成するクラスを示しています。タスクは、未完了の取引を取得して処理します。


  1. final class TransactionObserver {
  2. var updates: Task<Void, Never>? = nil
  3. init() {
  4. updates = newTransactionListenerTask()
  5. }
  6. deinit {
  7. // Cancel the update handling task when you deinitialize the class.
  8. updates?.cancel()
  9. }
  10. private func newTransactionListenerTask() -> Task<Void, Never> {
  11. Task(priority: .background) {
  12. for await verificationResult in Transaction.updates {
  13. self.handle(updatedTransaction: verificationResult)
  14. }
  15. }
  16. }
  17. private func handle(updatedTransaction verificationResult: VerificationResult<Transaction>) {
  18. guard case .verified(let transaction) = verificationResult else {
  19. // Ignore unverified transactions.
  20. return
  21. }
  22. if let revocationDate = transaction.revocationDate {
  23. // Remove access to the product identified by transaction.productID.
  24. // Transaction.revocationReason provides details about
  25. // the revoked transaction.
  26. <#...#>
  27. } else if let expirationDate = transaction.expirationDate,
  28. expirationDate < Date() {
  29. // Do nothing, this subscription is expired.
  30. return
  31. } else if transaction.isUpgraded {
  32. // Do nothing, there is an active transaction
  33. // for a higher level of service.
  34. return
  35. } else {
  36. // Provide access to the product identified by
  37. // transaction.productID.
  38. <#...#>
  39. }
  40. }
  41. }

updates の視聴者はアプリの起動時に未完了の取引を 1 回だけ受信しますが、unfinished の視聴者を使用していつでもアプリの未完了の取引を取得できます。取引の終了については、finish() を参照してください。





以下も見よ


関連した文書


あなたのアプリでサブスクリプション提供コードをサポート
(Supporting subscription offer codes in your app)

App Store またはあなたのアプリ内でオファーコードを利用する顧客にサブスクリプションサービスを提供します。



取引の履歴と権利


struct Transaction

顧客があなたのアプリ内で製品を購入したことを示す情報。


static var all: Transaction.Transactions

あなたのアプリのすべての顧客の取引を発行するシーケンス。


static var currentEntitlements: Transaction.Transactions

顧客にアプリ内購入とサブスクリプションの権利を与える最新の取引のシーケンス。














トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ