0

我正在使用已弃用的 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 的例子。不确定我是否需要更改它

4

1 回答 1

1

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

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

你会得到一个委托回调。您可能想要创建一个带有响应的字典:

- (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,但这是基本思想。

于 2015-07-14T17:17:04.343 回答