将app购买字符串标识符更改为对象(ios 5上已弃用)

时间:2013-07-12 13:46:48

标签: iphone ios ipad in-app-purchase

我需要将此字符串方法更改为SKProduct对象,因为它在我的应用上已被弃用(ios 5)

(注意:这是在InAppRageIAPHelper类上实现的)

 - (void)buyProductIdentifier2:(NSString *)productIdentifier {

        srtProduct = [productIdentifier copy];

    NSLog(@"Buying %@...", productIdentifier);

    SKPayment *payment = [SKPayment paymentWithProductIdentifier:productIdentifier];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}

然后,当你点击买:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(alertView.tag == 1)
    {
        NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
        if([title isEqualToString:@"Cancel"])
        {
            if ([delegate respondsToSelector:@selector(purchaseCancelled)]) {
                [delegate purchaseCancelled];
            }
        }
        else if([title isEqualToString:@"Buy"])
        {
            [self buyProductIdentifier2:srtProduct];
        }
    }
}

有人可以解释一下要改变什么吗?

2 个答案:

答案 0 :(得分:1)

您可以使用此链接。它提供了您想要的示例代码。 http://www.raywenderlich.com/23266/in-app-purchases-in-ios-6-tutorial-consumables-and-receipt-validation

在IAPHelper.m中找到此方法 - (无效)buyProduct:(SKProduct *)product {

NSLog(@"Buying %@...", product.productIdentifier);

SKPayment * payment = [SKPayment paymentWithProduct:product];
[[SKPaymentQueue defaultQueue] addPayment:payment];

}

答案 1 :(得分:0)

快速查看documentation后:看起来您必须使用产品标识符执行SKProductsRequest以获取SKProduct,然后您可以继续使用SKPayment