0

我使用此代码来处理我的应用内购买:

#pragma mark StoreKit Delegate

-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
    switch (transaction.transactionState) {
        case SKPaymentTransactionStatePurchasing:

            {

            // show wait view here
           // statusLabel.text = @"Processing...";

                }
            break;

        case SKPaymentTransactionStatePurchased:

                {

            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            // remove wait view and unlock feature 2
           // statusLabel.text = @"Done!";
            UIAlertView *tmp = [[UIAlertView alloc]
                                initWithTitle:@"Complete"
                                message:@"You have unlocked Feature 2!"
                                delegate:self
                                cancelButtonTitle:nil
                                otherButtonTitles:@"Ok", nil];
            [tmp show];



            NSError *error = nil;
            [SFHFKeychainUtils storeUsername:@"IAPStoreSave" andPassword:@"whatever" forServiceName:kStoredData updateExisting:YES error:&error];

            // apply purchase action  - hide lock overlay and

                    [self.lockImage removeFromSuperview];

            // do other thing to enable the features

                    }
            break;

        case SKPaymentTransactionStateRestored:
            {

            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            // remove wait view here
           // statusLabel.text = @"";

                }
            break;

        case SKPaymentTransactionStateFailed:

            {

            if (transaction.error.code != SKErrorPaymentCancelled) {
                NSLog(@"Error payment cancelled");
            }
            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            // remove wait view here
           // statusLabel.text = @"Purchase Error!";

            }
            break;

        default:
            {

                 }
            break;
    }
}
}

-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{

// remove wait view here
    // statusLabel.text = @"";

SKProduct *validProduct = nil;
int count = [response.products count];

if (count>0) {
    validProduct = [response.products objectAtIndex:0];

    SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.app.ID"];
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];


} else {
    UIAlertView *tmp = [[UIAlertView alloc]
                        initWithTitle:@"Not Available"
                        message:@"No products to purchase"
                        delegate:self
                        cancelButtonTitle:nil
                        otherButtonTitles:@"Ok", nil];
    [tmp show];

}


}
-(void)requestDidFinish:(SKRequest *)request
 {

}

-(void)request:(SKRequest *)request didFailWithError:(NSError *)error
 {
       NSLog(@"Failed to connect with error: %@", [error localizedDescription]);
}

并以这种方式启动它:

SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"com.app.ID"]];


            request.delegate = self;

            [request start];

在我的iTunes Connect中,我使用我输入的产品ID设置了应用内,状态为“准备提交”,并且还显示:“您的第一个应用内购买必须使用新的应用程序版本。从“版本详细信息”页面的“应用内购买”部分中选择它们,然后单击“准备上传二进制文件”。当我开始请求时,警报 NO PRODUCT AVAILABLE 总是出现。我究竟做错了什么??

4

1 回答 1

0

您确定捆绑 ID 与 Itunes Connect 上的应用程序相同吗?其次要检查的是应用程序配置文件(如果它处理 IAP) - 我认为这可能是原因。让我知道。

于 2013-07-11T21:41:40.977 回答