型プロパティ
updates
システムがアプリ外部または他のデバイスで発生する取引を作成または更新するときに取引を発行する非同期シーケンス。
iOS 15.0+ iPadOS 15.0+
macOS 12.0+
tvOS 15.0+
VisionOS 1.0+
WatchOS 8.0+
以下で言及
あなたのアプリで再獲得提供をサポート
(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 を作成するクラスを示しています。タスクは、未完了の取引を取得して処理します。
- final class TransactionObserver {
var updates: Task<Void, Never>? = nil
init() {
updates = newTransactionListenerTask()
}
deinit {
// Cancel the update handling task when you deinitialize the class.
updates?.cancel()
}
private func newTransactionListenerTask() -> Task<Void, Never> {
Task(priority: .background) {
for await verificationResult in Transaction.updates {
self.handle(updatedTransaction: verificationResult)
}
}
}
private func handle(updatedTransaction verificationResult: VerificationResult<Transaction>) {
guard case .verified(let transaction) = verificationResult else {
// Ignore unverified transactions.
return
}
if let revocationDate = transaction.revocationDate {
// Remove access to the product identified by transaction.productID.
// Transaction.revocationReason provides details about
// the revoked transaction.
<#...#>
} else if let expirationDate = transaction.expirationDate,
expirationDate < Date() {
// Do nothing, this subscription is expired.
return
} else if transaction.isUpgraded {
// Do nothing, there is an active transaction
// for a higher level of service.
return
} else {
// Provide access to the product identified by
// transaction.productID.
<#...#>
}
}
- }
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
顧客にアプリ内購入とサブスクリプションの権利を与える最新の取引のシーケンス。
トップへ
トップへ
トップへ
トップへ
トップへ
トップへ
トップへ
トップへ
トップへ
トップへ
トップへ
トップへ
トップへ
トップへ
トップへ
トップへ
トップへ
トップへ