gpt4 book ai didi

ios - 我将如何为 SKPaymentQueue 使用未弃用的 API?

转载 作者:行者123 更新时间:2023-11-29 01:51:03 27 4
gpt4 key购买 nike

我正在使用已弃用的 API,我想更新我的代码以使用未弃用的代码。

所以我的大问题是如何获得响应列表?

- (void) buyFeature:(NSString*) featureId
{
// SKProduct *myProduct;
if ([SKPaymentQueue canMakePayments])
{
SKPayment *payment = [SKPayment paymentWithProductIdentifier:featureId];
// SKPayment *payment = [SKPayment paymentWithProduct:myProduct];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
else
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"purchaseDone" object:nil];

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"You are not authorized to purchase from AppStore"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
}
}

- (void) purchase: (int) productIndex {
[self buyFeature: [aryProductIDs objectAtIndex: productIndex]];
}

aryProductIDs 在 (id)init 下定义

aryProductIDs = [[NSMutableArray alloc] initWithObjects: @"iap_100OrangeDollars",
@"iap_1",
@"iap_2",
@"iap_1month",
@"iap_3month",
@"iap_6month",
@"iap_12month",
@"iap_1lifetime",
nil];

我不确定要为 myProduct 使用什么(类型 SKProduct)。

我见过很多使用 NSSet 而不是 NSMutableArray 的例子。不确定是否需要更改它

最佳答案

首先您需要获取所有产品的产品信息:

NSSet *productsToRequest = [NSSet setWithArray:aryProductIDs];
SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers:productsToRequest];
request.delegate = self;
[request start];

您将收到委托(delegate)回调。你可能想用响应创建一个字典:

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
for (SKProduct *product in response.products)
{
dict[product.productIdentifier] = product;
}
self.products = dict;
}

您可能想查看响应并检查是否还有 invalidProductIdentifiers,但这是基本思路。

关于ios - 我将如何为 SKPaymentQueue 使用未弃用的 API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31412117/

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