我已经制作了IAP演示,并且我已经在Apple帐户中注册了我的演示应用程序,我还添加了产品信息,说明,app-id,title,priceTier,沙盒帐户,用于测试付款流程在演示中描述。我现在面临两个问题: -
a)就像popUp第一次要求apple-id /密码一样,我提供了两个值。它将显示我是否要确认我的付款,并在该弹出窗口中显示产品名称和产品价格。单击确定后,我甚至没有收到任何来自Apple的邮件,所以我如何证明我是否已成功付款。
b)我还想在购买产品时更改登录ID。但是每次默认情况下取我之前的ID并只显示密码框以输入密码。如何重置此设置?就像我已经尝试重置模拟器并再次在iTunes中的苹果a / c中添加新产品一样。所以,如果有任何人有任何想法请随意提供帮助。在下面分享我的代码: -
-(void)fetchAvailableProducts{
if ([SKPaymentQueue canMakePayments])
{
SKProductsRequest *request = [[SKProductsRequest alloc]
initWithProductIdentifiers:
[NSSet setWithObject:kTutorialPointProductID]];
request.delegate = self;
[request start];
}
else
NSLog(@"Please enable In App Purchase in Settings") ;
}
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
NSArray *products = response.products;
if (products.count != 0)
{
_product = products[0];
NSLog(@"procudt info is %@",_product.localizedTitle);
// _buyButton.enabled = YES;
// _productTitle.text = _product.localizedTitle;
// _productDescription.text = _product.localizedDescription;
[self purchaseProducts];
} else {
//_productTitle.text = @"Product not found";
}
products = response.invalidProductIdentifiers;
for (SKProduct *product in products)
{
NSLog(@"Product not found: %@", product);
}
}
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchased:
[[SKPaymentQueue defaultQueue]
finishTransaction:transaction];
NSLog(@"Transaction complete");
break;
case SKPaymentTransactionStateFailed:
NSLog(@"Transaction Failed");
[[SKPaymentQueue defaultQueue]
finishTransaction:transaction];
break;
default:
break;
}
}
}
首先,我只是使用我的产品ID获取产品,并且我在委托方法中获得响应,如果计数> 0,那么" purchaseProducts"方法将被调用。但问题是我的委托方法没有被调用,在点击&#34之后没有发生任何事情;好的"购买该产品。请分享您的想法。
答案 0 :(得分:2)
嗨按照给定的步骤,希望它有效 -
首先检查用户是否可以付款 -
-(void)checkForPayement{
//First check if user can make payments
if (![SKPaymentQueue canMakePayments]) {
// Show the error that user can't make payments.
}else{
// Make the product request on App Store
SKProductsRequest *productRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:IAP_PRODUCT_ID]]; // IAP_PRODUCT_ID is the product id which you got when you register the in-app-purchase
productRequest.delegate = self;
[productRequest start];
}
}
如果产品可用,您将通过以下方法获得回复 -
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
if (response.products.count > 0) {
SKProduct *validProduct = [response.products objectAtIndex:0];
[self purchase:validProduct];
} else {
// Product is not available so please cross check about the IAP_PRODUCT_ID
}
}
如果请求失败,您将通过以下方法获得回调 -
-(void)request:(SKRequest *)request didFailWithError:(NSError *)error{
// Check here for the error
}
开始购买
- (void)purchase:(SKProduct *)product{
SKPayment *payment = [SKPayment paymentWithProduct:product];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
}
您将获得给定方法的回调,并且您可以检查交易的状态 -
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray<SKPaymentTransaction *> *)transactions{
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
DDLogVerbose(@"Purchasing");
break;
case SKPaymentTransactionStateFailed:
if (transaction.error.code == SKErrorPaymentCancelled) {
// User has cancelled the transaction
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
DDLogVerbose(@"Restored");
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStatePurchased:
{
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
// Payment has been done and you should provide the purchased content or you may verify the receipt also
DDLogVerbose(@"Purchased");
}
break;
default:
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
}
}
}
如果您想要更高的安全性,那么您也可以Verify receipt from app store
解决您的问题
一个。在沙盒环境中测试应用内购买时,您将无法获得任何用于付款确认的邮件,您可以在Storekit updatedTransactions委托方法中检查您的付款状态。在Sandbox环境中不会扣除任何余额。输入沙盒帐户详细信息后,如果您可以登录,还要查看iTunes帐户?如果没有,您的ID可能无法验证,请验证您的身份。
湾在尝试应用内购买之前,只需在设置中注销苹果ID即可。 iTunes&amp;应用商店。点击苹果ID并单击注销。当您启动应用内购买时,请输入沙箱帐户凭据,并且不要在实际生产环境中登录沙盒帐户,因为它可能会使您的沙箱帐户无效。