【问题标题】:How would I use non deprecated API for SKPaymentQueue?我将如何为 SKPaymentQueue 使用非弃用 API?
【发布时间】:2015-07-14 16:20:34
【问题描述】:

我正在使用已弃用的 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 的例子。不知道要不要改

【问题讨论】:

    标签: ios ios8 in-app-purchase skproduct skpaymenttransaction


    【解决方案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,但这是基本想法。

    【讨论】:

    • 它没有用。 productsRequestWithProductIdentifiers 给了我一个警告
    • 哎呀,那是因为我创建了自己的工厂方法(用于单元测试)而不是使用 alloc / init。以上更新。
    猜你喜欢
    • 2017-08-05
    • 2016-10-24
    • 2021-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 2022-11-09
    • 2020-06-26
    相关资源
    最近更新 更多