gpt4 book ai didi

ios - 使用 Apple 托管的内容进行应用内购买时更新内容

转载 作者:IT王子 更新时间:2023-10-29 08:01:22 24 4
gpt4 key购买 nike

我正在使用 Apple 托管的内容实现应用内购买。之前我使用 Urban Airship 来托管我的内容,并使用他们的 SDK 来提供应用内商店 UI 和购买功能。

由于 Urban Airship 在今年 7 月停止了对 IAP 的支持,我需要更换它。

Urban Airship SDK 支持更新购买的内容。我看到 StoreKit 提供了此功能(至少在一定程度上),但不确定如何正确实现内容更新本身。

SKProduct 有一个 downloadContentVersion,它指定可从 Apple 下载的内容的版本。我跟踪应用程序中当前下载的版本 - 所以我知道何时有可用更新。

我遇到的问题是如何实际下载更新的内容?

我的第一个想法是为该特定购买进行恢复,但似乎无法恢复个别产品(仅所有产品)。第二个想法是重新购买产品,但这会向用户显示一个警告,表明他们将再次收费——但是,他们不会被收费,因为在重新购买后会显示另一个警告,通知用户内容已经购买并将免费重新下载——但对我来说,这感觉是一种糟糕的用户体验,他们可能不一定知道在同意购买之前他们不会再次被收费。

文档说不要自己创建 SKDownload 实例,所以我不能只创建一个实例并将其添加到下载队列中。

在使用 Apple 托管的内容时,我应该如何为应用内购买实现内容更新?

最佳答案

感谢 Jasarien 就此问题联系 Apple。以下是一些示例代码,适用于发现此主题并试图了解如何更新应用内内容的任何人。

首先,当您收到来自 SKProductsRequest 的响应时,请检查 downloadContentVersion 与您之前下载内容的版本。您可以使用如下代码获取现有内容的内容版本:

NSString *pathToYourContent = @""; // Put your path here
NSString *contentInfoPath = [pathToYourContent stringByAppendingPathComponent:@"ContentInfo.plist"];
NSDictionary *contentInfo = [NSDictionary dictionaryWithContentsOfFile:contentInfoPath];

NSString *contentVersion = [contentInfo objectForKey:@"ContentVersion"];
NSString *iapProductIdentifier = [contentInfo objectForKey:@"IAPProductIdentifier"];

然后,如果您发现该版本已更改,您可以提示用户进行更新。如果他们同意,则开始恢复。

[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

然后,当交易开始到来时,您需要决定接受哪些交易,忽略哪些交易。在这个下载歌曲内容的应用示例中,我有一个 YHSongVersion 类,它存储我们下载的所有歌曲的 ID 和版本,这些存储在数组 self.ownedSongVersions 中。此示例将接受版本号不同或我们未获得内容的任何恢复。

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStateFailed:
break;

case SKPaymentTransactionStatePurchased:
[self provideContentForTransaction:transaction];
break;

case SKPaymentTransactionStatePurchasing:
break;

case SKPaymentTransactionStateRestored:
[self restorePurchaseIfRequired:transaction];
break;
}
}

}

/// On a restore download the content if either we don't have the content or the version number has changed.
- (void)restorePurchaseIfRequired:(SKPaymentTransaction *)transaction {
BOOL haveSong = NO;
SKDownload *download = [transaction.downloads objectAtIndex:0];
for (YHSongVersion *ownedSongVersion in self.ownedSongVersions) {
BOOL isSongForThisDownload = [ownedSongVersion.iapProductIdentifier isEqualToString:download.contentIdentifier];
if (isSongForThisDownload) {
haveSong = YES;
BOOL hasDifferentVersionNumber = ![ownedSongVersion.contentVersion isEqualToString:download.contentVersion];
if (hasDifferentVersionNumber) {
[self provideContentForTransaction:transaction];
}
else {
// Do nothing
[self completeTransaction:transaction];
NSLog(@"Ignoring restore for %@", ownedSongVersion.iapProductIdentifier);
}
}
}

if (!haveSong) {
[self provideContentForTransaction:transaction];
}
}

关于ios - 使用 Apple 托管的内容进行应用内购买时更新内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17009813/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com