我试图关注此tutorial,但我收到此错误:
Error Domain=SKErrorDomain Code=0 "Cannot connect to iTunes Store" UserInfo=0x15c02260 {NSLocalizedDescription=Cannot connect to iTunes Store}
我已经在iTunes Connect中创建了一个测试用户,但连接到新用户的弹出窗口甚至都没有显示。我已经尝试重置模拟器,从模拟器中删除应用程序,从应用程序支持文件中删除文件,以及有关此错误的其他主题中提供的其他解决方案。
我的最后一个假设是我的代码在某种程度上是错误的,我没有看到。
这是我的代码:
-(id)init
{
if (self = [super init]) {
NSLog(@"game store loaded");
if ([SKPaymentQueue canMakePayments])
{
NSLog(@"can make payments");
SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject:@"teste2"]];
productsRequest.delegate = self;
[productsRequest start];
//start Buying/buy button
//SKProduct *selectedProduct = @"teste2";
//SKPayment *payment = [SKPayment paymentWithProduct:selectedProduct];
SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.rundogrun.prod001"];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
else {
NSLog(@"Please enable In App Purchase in Settings");
}
}
return self;
}
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse: (SKProductsResponse *)response {
SKProduct *validProduct = nil;
int count = [response.products count];
if (count > 0) {
NSLog(@"%d products available", count);
validProduct = [response.products objectAtIndex:0];
} else if (!validProduct) {
NSLog(@"No products available");
}
}
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
NSLog(@"purchasing");
//avisa usuario que o produto esta sendo comprado
break;
case SKPaymentTransactionStatePurchased:
NSLog(@"purchased");
//faz alguma coisa quando o produto for comprado
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
NSLog(@"restored");
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
NSLog(@"failed");
if (transaction.error.code != SKErrorPaymentCancelled) {
NSLog(@"An Error Encoutered %@", transaction.error.description );
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
default:
break;
}
}
}
答案 0 :(得分:0)
在iOS 7中,IAP在模拟器中不起作用。我跑上设备,它工作得很好!