在应用程序购买没有得到任何产品

时间:2014-03-16 06:52:44

标签: ios iphone ios7 in-app-purchase storekit

我一直在尝试进行应用内购买工作。目前我在应用商店中有一个应用程序(版本1.1)。我想在该版本中发布另一个版本(V 1.2),我希望在应用购买中集成。我为此创造了一个产品。但是当我尝试加载所有产品时,它表明没有产品。

V1.2采用准备上传二进制文件的形式。我在应用购买时已关联。我只想在App Purchase中测试。我已从设备(MAC + iPhone)中删除了所有配置文件。目前我只安装了一个配置文件。

这是我的代码:

-(void)fetchAvailableProducts{
    NSSet *productIdentifiers = [NSSet
                                 setWithObjects:bundle_identifier,nil];
    productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
    productsRequest.delegate = self;
    [productsRequest start];
}

- (void)requestDidFinish:(SKRequest *)request {
    NSLog(@"purchase request finished");
}

- (void)request:(SKRequest *)request didFailWithError:(NSError *)error {
    NSLog(@"%@", [error description]);
}

- (BOOL)canMakePurchases
{
    return [SKPaymentQueue canMakePayments];
}
- (void)purchaseMyProduct:(SKProduct*)product{
    if ([self canMakePurchases]) {
        SKPayment *payment = [SKPayment paymentWithProduct:product];
        [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
        [[SKPaymentQueue defaultQueue] addPayment:payment];
    }
    else{
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
                                  @"Purchases are disabled in your device" message:nil delegate:
                                  self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
        [alertView show];
    }
}

#pragma mark StoreKit Delegate

-(void)paymentQueue:(SKPaymentQueue *)queue
updatedTransactions:(NSArray *)transactions {
    for (SKPaymentTransaction *transaction in transactions) {
        switch (transaction.transactionState) {
            case SKPaymentTransactionStatePurchasing:
                NSLog(@"Purchasing");
                break;
            case SKPaymentTransactionStatePurchased:
                if ([transaction.payment.productIdentifier
                     isEqualToString:bundle_identifier]) {
                    NSLog(@"Purchased ");
                    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
                                              @"Purchase is completed succesfully" message:nil delegate:
                                              self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
                    [alertView show];
                }
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;
            case SKPaymentTransactionStateRestored:
                NSLog(@"Restored ");
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:
                NSLog(@"Purchase failed ");
                break;
            default:
                break;
        }
    }
}

-(void)productsRequest:(SKProductsRequest *)request
    didReceiveResponse:(SKProductsResponse *)response
{
    SKProduct *validProduct = nil;
    int count = [response.products count];
    NSLog(@"%@",response.products);
    if (count>0) {
        validProducts = response.products;
        validProduct = [response.products objectAtIndex:0];
        if ([validProduct.productIdentifier
             isEqualToString:bundle_identifier]) {
        }
    } else {
        UIAlertView *tmp = [[UIAlertView alloc]
                            initWithTitle:@"Not Available"
                            message:@"No products to purchase"
                            delegate:self
                            cancelButtonTitle:nil
                            otherButtonTitles:@"Ok", nil];
        [tmp show];
    }
}

我想知道启用应用内购买的正确程序是什么以及我做错了什么?应该做些什么?

3 个答案:

答案 0 :(得分:1)

我解决了这个问题,所以我将其添加为答案。

我混淆了包标识符和产品标识符。我的代码是正确的,我提供了包标识符而不是产品标识符,这就是我没有得到任何产品的原因。

NSSet *productIdentifiers = [NSSet
                                 setWithObjects:product_identifier,nil];
productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];

在上面的代码中使用product_identifier(s)。因为我只创建了一个产品,所以我使用单个元素来构建集合。

答案 1 :(得分:0)

您的代码看起来是正确的。您是否确认您的应用内商品ID与bundle_id变量中的值完全匹配?

答案 2 :(得分:0)

 + (RageIAPHelper *)sharedInstance {
static dispatch_once_t once;
static RageIAPHelper * sharedInstance;
dispatch_once(&once, ^{
    NSSet * productIdentifiers = [NSSet       setWithObject:kMDPulseSubscriptionProductIdentifier];
    sharedInstance = [[self alloc] initWithProductIdentifiers:productIdentifiers];
});
return sharedInstance;
   }

你得到了产品清单, 但你必须在真实的​​设备上进行测试。