目前,我正在开发应用内购买功能,而且我正处于错误
之下“Error Domain = SKErrorDomain Code = 3”无法连接到iTunes Store“UserInfo = 0x1aaf40 {NSLocalizedDescription =无法连接到iTunes Store}”
这是一步。
1)首先,我创建了一个“inAppPro”应用程序,它位于(状态):“准备上传”
2)我添加了4种非消费品。并填写相关细节。
3)我还为测试应用内购买产品创建了测试用户(沙盒)。
4)我还通过启用inApp Purchase创建了配置文件。
5)我还创建了没有(*)外卡的APP ID。
以下是我正在使用的代码。
- (void)viewDidLoad
{
Detail1 *observer = [[Detail1 alloc] init];
[[SKPaymentQueue defaultQueue] addTransactionObserver:observer];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
if ([SKPaymentQueue canMakePayments])
{
NSString *product = [NSString stringWithFormat:@"com.companyname.inAppDemo.module%d",ApplicationDelegate.objectID];
NSLog(@"In-App product for request = %@", product);
SKPayment *payment = [SKPayment paymentWithProductIdentifier:product];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"MyApp" message:@"You are not authorized to purchase from AppStore"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
}
}
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[self restoreTransaction:transaction];
default:
break;
}
}
}
- (void) failedTransaction: (SKPaymentTransaction *)transaction
{
if (transaction.error.code != SKErrorPaymentCancelled)
{
// Optionally, display an error here.
NSLog(@"%@",transaction.error);
}
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
- (void) completeTransaction: (SKPaymentTransaction *)transaction
{
//[[MKStoreManager sharedManager] provideContent: transaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
- (void) restoreTransaction: (SKPaymentTransaction *)transaction
{
//[[MKStoreManager sharedManager] provideContent: transaction.originalTransaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
-(IBAction)btnpurchase:(id)sender
{
NSLog(@"ProductStatus = %@", ApplicationDelegate.productStatus);
if ([ApplicationDelegate.productStatus isEqualToString:@"FREE"])
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"This is free for you so ENJOY it!!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,nil];
[alert show];
[alert release];
}
else if ([ApplicationDelegate.productStatus isEqualToString:@"PAID"])
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"You have already purchase it!!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,nil];
[alert show];
[alert release];
}
else
{
NSLog(@"Detail1 id for product = %d", ApplicationDelegate.objectID);
NSString *product = [NSString stringWithFormat:@"com.companyname.inAppDemo.module%d",ApplicationDelegate.objectID];
NSLog(@"In-App product-id = %@", product);
SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObjects:product,nil]];
request.delegate = self;
[request start];
}
}
请有人帮助我。
提前致谢。
答案 0 :(得分:3)
您必须在“合同,税务和银行业务”部分中签署有效合同。 当然,请确保您使用正确的配置文件,并且已在App Purchase中为该ID启用,并且(最后)您已在iTunes Connect中添加了可购买的项目(您所做的,如屏幕截图所示)。 / p>