我们正在开发一个应用程序,当然,它使用应用内购买(IAP)。
我按照指南完成了启用iap的所有步骤,并且一切都运行正常,直到我想进行购买。
以下是部分代码:
MainViewController.m
但是,一旦我点击“购买”按钮,没有对话框弹出或要求我提供我的凭据。只有“SKPaymentTransactionStatePurchasing”被记录下来。
而且我:
- ...已在设置/商店窗格中注销
- ...正在使用正确的配置文件
- ...非常绝望
任何人可以帮忙吗?
-(void)viewDidLoad {
if ([SKPaymentQueue canMakePayments]) {
MyStoreObserver *observer = [[MyStoreObserver alloc] init];
[[SKPaymentQueue defaultQueue] addTransactionObserver:observer];
SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObjects: @"com.company.app.product1", @"com.company.app.product1", nil]];
request.delegate = self;
[request start];
}
};
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
for (SKProduct *prod in response.products) {
NSLog(@"%@ (%@)", prod.localizedTitle, prod.price);
}
[request release];
};
-(IBAction)clickBuy:(UIButton *)__sender {
SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.company.app.product1"];
[[SKPaymentQueue defaultQueue] addPayment:payment];
};
MyStoreObserver.m
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchased:
NSLog(@"SKPaymentTransactionStatePurchased");
break;
case SKPaymentTransactionStateFailed:
NSLog(@"SKPaymentTransactionStateFailed");
break;
case SKPaymentTransactionStateRestored:
NSLog(@"SKPaymentTransactionStateRestored");
break;
case SKPaymentTransactionStatePurchasing:
NSLog(@"SKPaymentTransactionStatePurchasing");
default:
break;
}
}
};
productRequest:
委托方法显示了两款产品的名称/价格,就像我在iTunes连接站点中输入的一样。但是,一旦我点击“购买”按钮,没有对话框弹出或要求我提供我的凭据。只有“SKPaymentTransactionStatePurchasing”被记录下来。
而且我:
- ...已在设置/商店窗格中注销
- ...正在使用正确的配置文件
- ...非常绝望
任何人可以帮忙吗?