iPhone Store Kit“无法连接到 itunes 商店”无法连接到 itunes 商店”
我已经在我的 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];
I have implemented storeKit in my iOS app, this is the code:
-(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;
}
}
}
this comes on the 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];
}
the product identifier are currect but i keep gettin this error called from the switch statement
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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试以下操作:
编辑:
这也可以帮助您
错误域=SKErrorDomain代码=0“操作无法完成。 (SKErrorDomain 错误 0。)”
Try following things:
EDIT:
This could also help you
Error Domain=SKErrorDomain Code=0 “Operation could not be completed. (SKErrorDomain error 0.)”
购买失败是因为交易在技术上失败,这并不是特别因为无法连接......这可能是由于多种原因造成的。仔细检查产品标识符是否正确。我认为您的问题很可能是您没有使用链接到您的应用程序所使用的应用程序 ID 的开发证书来签署您的应用程序。在 iTunes Connect 中,您的应用程序链接到哪个应用程序 ID?它需要是该应用程序特有的应用程序 ID(即 com.ChillySky.InAppPurchaseApp,而不是 com.ChillySky.*),没有通配符!此外,您需要生成特殊的开发证书才能在您的设备上测试此应用程序。它必须链接到正确的应用程序 ID!如果其中任何一项不正确,您的应用内购买将无法完成。这对我来说是最大的问题。
The purchase is failing because the transaction is technically failing, and this is not specifically due to the fact that it cannot connect... it can be due to a number of reasons. Double check that the product identifier is correct. I think that your issue is most likely that you are not signing your app with a development certificate that is linked to the App ID used for your app. In iTunes Connect, what app ID is your app linked to? It needs to be an app ID SPECIFICALLY for that app (i.e. com.ChillySky.InAppPurchaseApp, NOT com.ChillySky.*), no wildcards! Also, you need to generate a special development certificate to test this app on your device. IT MUST BE LINKED TO THE CORRECT APP ID!! If any of this is not correct, your in app purchase will not go through. This was the biggest issue for me.