我已经在我的 iOS 应用中实现了 storeKit,这是代码:
-(IBAction)Purchase:(id)sender{
SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"month"];
[[SKPaymentQueue defaultQueue]addTransactionObserver:self];
[[SKPaymentQueue defaultQueue]addPayment:payment];
}
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
SKProduct *VailProduct = nil;
int count = [response.products count];
if (count>0) {
VailProduct = [response.products objectAtIndex:0];
} else if (!VailProduct){
UIAlertView *theAlert = [[UIAlertView alloc]initWithTitle:@"LOG" message:@"No Products Are Availble!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[theAlert show];
[theAlert release];
}
}
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
break;
case SKPaymentTransactionStatePurchased:
[self EnableEmergencyCenter];
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
if (transaction.error.code != SKErrorPaymentCancelled) {
UIAlertView *theAlert = [[UIAlertView alloc]initWithTitle:@"LOG" message:[NSString stringWithFormat:@"%@",transaction.error] delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[theAlert show];
[theAlert release];
}
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
break;
}
}
}
这出现在 viewDidLoad 上:
if ([SKPaymentQueue canMakePayments])
{
// Display a store to the user.
UIAlertView *theAlert = [[UIAlertView alloc]initWithTitle:@"LOG" message:@"Device Can Make Payments!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[theAlert show];
[theAlert release];
SKProductsRequest *ProductRequst = [[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet setWithObject:@"month"]];
ProductRequst.delegate = self;
[ProductRequst start];
}
else {
// Warn the user that purchases are disabled.
UIAlertView *theAlert = [[UIAlertView alloc]initWithTitle:@"LOG" message:@"Device Can't Make Payments!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[theAlert show];
[theAlert release];
}
产品标识符是正确的,但我一直收到从 switch 语句调用的错误
case SKPaymentTransactionStateFailed:
if (transaction.error.code != SKErrorPaymentCancelled) {
UIAlertView *theAlert = [[UIAlertView alloc]initWithTitle:@"LOG" message:[NSString stringWithFormat:@"%@",transaction.error] delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[theAlert show];
[theAlert release];
最佳答案
尝试以下操作:
- 创建一个新的配置文件,安装它并使用它签署您的应用程序。有时,当您编辑旧配置文件时,它们不会真正更新,因此付款流程将无法正常工作。
- 如果您正确收到产品并且之前安装了应用程序的 iTunes 版本,则需要从设备中删除该应用程序并通过 XCode 安装它。
编辑:
这也可以帮助你
Error Domain=SKErrorDomain Code=0 “Operation could not be completed. (SKErrorDomain error 0.)”
关于iPhone Store Kit "cannot connect to itunes store"无法连接到 iTunes 商店”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7807099/