应用程序内购买无效,显示无产品

Kra*_*KAy 5 in-app-purchase ios

我正在学习Apple提供的应用程序内购买.所以我按照这个教程:http: //www.appcoda.com/in-app-purchase-tutorial/

我按照本教程中的所有步骤操作.首先,我创建了一个app id,然后使用该app id在iTunes中创建了一个应用程序.然后我创建了两个应用程序内购买,产品ID为"com.outlines.feature1"和"com.outlines.feature2",两者都是可消耗的.其余的代码我只是按照上面的教程中的步骤

import UIKit
import StoreKit

protocol IAPurchaceViewControllerDelegate {
    func didBuyColorsCollection(collectionIndex: Int)
}


class IAPurchaceViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, SKProductsRequestDelegate, SKPaymentTransactionObserver {

@IBOutlet weak var tblProducts: UITableView!

var delegate: IAPurchaceViewControllerDelegate!

var selectedProductIndex: Int!
var transactionInProgress = false

let productIdentifiers = NSSet(array: ["com.outlines.feature1", "com.outlines.feature2"])
 var product: SKProduct?
var productsArray = Array<SKProduct>()

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
    tblProducts.delegate = self
    tblProducts.dataSource = self

    //checks whether the In-App feature is activated or not
    requestProductInfo()

    SKPaymentQueue.defaultQueue().addTransactionObserver(self)
}

func requestProductInfo(){
    if SKPaymentQueue.canMakePayments() {
        let request = SKProductsRequest(productIdentifiers:
            productIdentifiers as! Set<String>)
        print("This is the request to be sent \(request)")
        request.delegate = self
        request.start()//calls productsRequest() function
    }
    else {
        print("Cannot perform In App Purchases.")
    }
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

// MARK: IBAction method implementation

@IBAction func dismiss(sender: AnyObject) {
    dismissViewControllerAnimated(true, completion: nil)
}


// MARK: UITableView method implementation

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}


func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return productsArray.count
}


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("idCellProduct", forIndexPath: indexPath) as UITableViewCell

    let product = productsArray[indexPath.row]
    cell.textLabel?.text = product.localizedTitle
    cell.detailTextLabel?.text = product.localizedDescription

    return cell
}


func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    selectedProductIndex = indexPath.row
    showActions()
    tableView.cellForRowAtIndexPath(indexPath)?.selected = false
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return 80.0
}




/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


func productsRequest(request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {
    if response.products.count != 0 {
        for product in response.products {
            productsArray.append(product as SKProduct)
        }

        tblProducts.reloadData()
    }
    else {
        print("There are no products.")
    }

    if response.invalidProductIdentifiers.count != 0 {
        print("Invalid "+response.invalidProductIdentifiers.description)
    }
}

func showActions() {
    if transactionInProgress {
        return
    }

    let actionSheetController = UIAlertController(title: "IAPDemo", message: "What do you want to do?", preferredStyle: UIAlertControllerStyle.ActionSheet)

    let buyAction = UIAlertAction(title: "Buy", style: UIAlertActionStyle.Default) { (action) -> Void in
        let payment = SKPayment(product: self.productsArray[self.selectedProductIndex] as SKProduct)
        SKPaymentQueue.defaultQueue().addPayment(payment)
        self.transactionInProgress = true
    }

    let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (action) -> Void in

    }

    actionSheetController.addAction(buyAction)
    actionSheetController.addAction(cancelAction)

    presentViewController(actionSheetController, animated: true, completion: nil)
}

func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
    for transaction in transactions as [SKPaymentTransaction] {
        switch transaction.transactionState {
        case SKPaymentTransactionState.Purchased:
            print("Transaction completed successfully.")
            SKPaymentQueue.defaultQueue().finishTransaction(transaction)
            transactionInProgress = false
            delegate.didBuyColorsCollection(selectedProductIndex)

        case SKPaymentTransactionState.Failed:
            print("Transaction Failed");
            SKPaymentQueue.defaultQueue().finishTransaction(transaction)
            transactionInProgress = false

        default:
            print(transaction.transactionState.rawValue)
        }
    }
}  
}
Run Code Online (Sandbox Code Playgroud)

没有错误,但是当我在iPhone上运行时,控制台显示:

This is the request to be sent <SKProductsRequest: 0x15d86210>
There are no products.
Invalid ["com.outlines.feature1", "com.outlines.feature2"]
Run Code Online (Sandbox Code Playgroud)

控制台没有显示任何产品,但我在iTunes ID中添加了两个应用内功能.这是截图: iTunes中的应用内购买

谁能告诉我我做错了什么?

Kra*_*KAy 34

我终于解决了.代码和应用程​​序内购买制作过程中没有错误.上传快照的早期解决方案也不是问题.

问题是协议,税收和烘焙中的合同.教程中没有提到它,但我们需要在iTunes中完成协议,税务和银行合同,这是我没有做过的.填写合同表格后,将予以处理.然后合同生效,然后将识别在iTunes中创建的应用内购买.

  • 我也有同样的问题.我已经填写了所有银行和税务信息,但我仍然没有提供任何产品.我已经设置了4-5小时前所需的所有信息,但仍然没有.需要更多时间吗? (2认同)

Don*_*one 15

要在您的设备上测试IAP,您不需要提交屏幕截图.只有在您提交应用时才需要它.

确保您对以下每个问题都回答"是":

  1. 您是否为应用程序ID启用了应用程序内购买?
  2. 你有没有检查过你的产品清仓?
  3. 您的项目的.plist捆绑ID是否与您的应用ID相匹配?
  4. 您是否为新的App ID生成并安装了新的配置文件?
  5. 您是否已使用此新配置文件将项目配置为代码签名?
  6. 您在制作SKProductRequest时是否使用完整的产品ID?
  7. 自从将产品添加到iTunes Connect后,您有几个小时的时间吗?
  8. 您是否尝试从设备中删除该应用并重新安装?
  9. 你的设备越狱了吗?如果是这样,您需要恢复IAP的越狱才能工作.

如果你对这些问题中的任何一个回答"否",那就是你的问题.

您正在使用tableView,请确保您已设置要在单元格中加载的正确参数.愿你的问题与tableview有关.